From 50b3929a7f8a2931f7c14c5b101e4ebb7d4d4bbe Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Tue, 20 Jul 2021 11:48:38 +0200 Subject: [PATCH] build: improve size checks --- package.json | 1 + scripts/check-size.js | 7 +- size-checks/{small.js => option-store.js} | 0 size-checks/rollup.config.js | 115 ++++++++++++---------- size-checks/setup-store.js | 5 + yarn.lock | 2 +- 6 files changed, 75 insertions(+), 55 deletions(-) rename size-checks/{small.js => option-store.js} (100%) create mode 100644 size-checks/setup-store.js diff --git a/package.json b/package.json index 32156d46..edf321a7 100644 --- a/package.json +++ b/package.json @@ -79,6 +79,7 @@ "brotli": "^1.3.2", "codecov": "^3.8.2", "conventional-changelog-cli": "^2.1.1", + "globby": "^11.0.4", "jest": "^26.6.3", "jest-mock-warn": "^1.1.0", "lint-staged": "^11.0.1", diff --git a/scripts/check-size.js b/scripts/check-size.js index 77439dcf..9ef1b04e 100644 --- a/scripts/check-size.js +++ b/scripts/check-size.js @@ -1,4 +1,5 @@ const fs = require('fs') +const globby = require('globby') const path = require('path') const chalk = require('chalk') const { gzipSync } = require('zlib') @@ -21,4 +22,8 @@ function checkFileSize(filePath) { ) } -checkFileSize(path.resolve(__dirname, '../size-checks/dist/small.js')) +const paths = globby.sync(path.resolve(__dirname, '../size-checks/dist/*.js')) + +for (const file of paths) { + checkFileSize(file) +} diff --git a/size-checks/small.js b/size-checks/option-store.js similarity index 100% rename from size-checks/small.js rename to size-checks/option-store.js diff --git a/size-checks/rollup.config.js b/size-checks/rollup.config.js index b8ff9e67..f5510fec 100644 --- a/size-checks/rollup.config.js +++ b/size-checks/rollup.config.js @@ -5,58 +5,67 @@ import resolve from '@rollup/plugin-node-resolve' import commonjs from '@rollup/plugin-commonjs' import { terser } from 'rollup-plugin-terser' -/** @type {import('rollup').RollupOptions} */ -const config = { - external: ['vue'], - output: { - file: path.resolve(__dirname, './dist/small.js'), - format: 'es', - }, - input: path.resolve(__dirname, './small.js'), - plugins: [ - replace({ - preventAssignment: true, - values: { - __DEV__: 'false', - 'process.env.NODE_ENV': JSON.stringify('production'), - // this is only used during tests - __TEST__: 'false', - // If the build is expected to run directly in the browser (global / esm builds) - __BROWSER__: 'true', - // is targeting bundlers? - __BUNDLER__: 'false', - __GLOBAL__: 'false', - // is targeting Node (SSR)? - __NODE_JS__: 'false', - __VUE_PROD_DEVTOOLS__: 'false', - }, - }), - ts({ - check: false, - tsconfig: path.resolve(__dirname, '../tsconfig.json'), - cacheRoot: path.resolve(__dirname, '../node_modules/.rts2_cache'), - tsconfigOverride: { - compilerOptions: { - sourceMap: false, - declaration: false, - declarationMap: false, - }, - exclude: ['__tests__', 'test-dts'], - }, - }), - resolve(), - commonjs(), - terser({ - format: { - comments: false, - }, - module: true, - compress: { - ecma: 2015, - pure_getters: true, - }, - }), - ], -} +/** @type {import('rollup').RollupOptions[]} */ +const config = ['option-store', 'setup-store'].map(createConfig) export default config + +/** + * + * @param {string} file + * @returns {import('rollup').RollupOptions} + */ +function createConfig(file) { + return { + external: ['vue'], + output: { + file: path.resolve(__dirname, `./dist/${file}.js`), + format: 'es', + }, + input: path.resolve(__dirname, `./${file}.js`), + plugins: [ + replace({ + preventAssignment: true, + values: { + __DEV__: 'false', + 'process.env.NODE_ENV': JSON.stringify('production'), + // this is only used during tests + __TEST__: 'false', + // If the build is expected to run directly in the browser (global / esm builds) + __BROWSER__: 'true', + // is targeting bundlers? + __BUNDLER__: 'false', + __GLOBAL__: 'false', + // is targeting Node (SSR)? + __NODE_JS__: 'false', + __VUE_PROD_DEVTOOLS__: 'false', + }, + }), + ts({ + check: false, + tsconfig: path.resolve(__dirname, '../tsconfig.json'), + cacheRoot: path.resolve(__dirname, '../node_modules/.rts2_cache'), + tsconfigOverride: { + compilerOptions: { + sourceMap: false, + declaration: false, + declarationMap: false, + }, + exclude: ['__tests__', 'test-dts'], + }, + }), + resolve(), + commonjs(), + terser({ + format: { + comments: false, + }, + module: true, + compress: { + ecma: 2015, + pure_getters: true, + }, + }), + ], + } +} diff --git a/size-checks/setup-store.js b/size-checks/setup-store.js new file mode 100644 index 00000000..8870abc5 --- /dev/null +++ b/size-checks/setup-store.js @@ -0,0 +1,5 @@ +import { createPinia, defineSetupStore } from '../dist/pinia.esm-bundler' + +createPinia() +// @ts-ignore +export default defineSetupStore() diff --git a/yarn.lock b/yarn.lock index f8e1fc79..7e74a269 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2780,7 +2780,7 @@ globals@^11.1.0: resolved "https://registry.yarnpkg.com/globals/-/globals-11.12.0.tgz#ab8795338868a0babd8525758018c2a7eb95c42e" integrity sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA== -globby@^11.0.3: +globby@^11.0.3, globby@^11.0.4: version "11.0.4" resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.4.tgz#2cbaff77c2f2a62e71e9b2813a67b97a3a3001a5" integrity sha512-9O4MVG9ioZJ08ffbcyVYyLOJLk5JQ688pJ4eMGLpdWLHq/Wr1D9BlriLQyL0E+jbkuePVZXYFj47QM/v093wHg== -- 2.47.2