diff --git a/.github/workflows/test-multiple-builds.yml b/.github/workflows/test-multiple-builds.yml index 404b1687..20ed0ed5 100644 --- a/.github/workflows/test-multiple-builds.yml +++ b/.github/workflows/test-multiple-builds.yml @@ -12,7 +12,7 @@ jobs: strategy: fail-fast: false matrix: - build: [cjs, esm, umd] # [cjs, esm, umd, system] + build: [cjs, esm] env: [development] # [development, production] steps: - uses: actions/checkout@v2 @@ -44,18 +44,6 @@ jobs: sed -i~ "1s/^/import.meta.env=import.meta.env||{};import.meta.env.MODE='${NODE_ENV}';/" tests/*.ts tests/*.tsx env: NODE_ENV: ${{ matrix.env }} - - name: Patch for UMD - if: ${{ matrix.build == 'umd' }} - run: | - sed -i~ "s/\/src\(.*\)\.ts/\/dist\/umd\1.${NODE_ENV}.js/" package.json - env: - NODE_ENV: ${{ matrix.env }} - - name: Patch for SystemJS - if: ${{ matrix.build == 'system' }} - run: | - sed -i~ "s/\/src\(.*\)\.ts/\/dist\/system\1.${NODE_ENV}.js/" package.json - env: - NODE_ENV: ${{ matrix.env }} - name: Test ${{ matrix.build }} ${{ matrix.env }} run: | yarn test:ci diff --git a/babel.config.js b/babel.config.js deleted file mode 100644 index fa15c8a7..00000000 --- a/babel.config.js +++ /dev/null @@ -1,28 +0,0 @@ -module.exports = (api, targets) => { - // https://babeljs.io/docs/en/config-files#config-function-api - const isTestEnv = api.env('test') - - return { - babelrc: false, - ignore: ['./node_modules'], - presets: [ - [ - '@babel/preset-env', - { - loose: true, - modules: isTestEnv ? 'commonjs' : false, - targets: isTestEnv ? { node: 'current' } : targets, - }, - ], - ], - plugins: [ - [ - '@babel/plugin-transform-react-jsx', - { - runtime: 'automatic', - }, - ], - ['@babel/plugin-transform-typescript', { isTSX: true }], - ], - } -} diff --git a/package.json b/package.json index 9c80940c..08df6eb7 100644 --- a/package.json +++ b/package.json @@ -116,7 +116,6 @@ "@rollup/plugin-babel": "^6.0.4", "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-replace": "^5.0.5", - "@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-typescript": "^11.1.5", "@testing-library/react": "^14.0.0", "@types/jsdom": "^21.1.4", diff --git a/rollup.config.js b/rollup.config.js index 9d12aee4..1534ddad 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -3,10 +3,8 @@ const alias = require('@rollup/plugin-alias') const babelPlugin = require('@rollup/plugin-babel') const resolve = require('@rollup/plugin-node-resolve') const replace = require('@rollup/plugin-replace') -const terser = require('@rollup/plugin-terser') const typescript = require('@rollup/plugin-typescript') const { default: esbuild } = require('rollup-plugin-esbuild') -const createBabelConfig = require('./babel.config.js') const extensions = ['.js', '.ts', '.tsx'] const { root } = path.parse(process.cwd()) @@ -23,7 +21,13 @@ function external(id) { function getBabelOptions(targets) { return { - ...createBabelConfig({ env: (env) => env === 'build' }, targets), + babelrc: false, + ignore: ['./node_modules'], + presets: [['@babel/preset-env', { loose: true, modules: false, targets }]], + plugins: [ + ['@babel/plugin-transform-react-jsx', { runtime: 'automatic' }], + ['@babel/plugin-transform-typescript', { isTSX: true }], + ], extensions, comments: false, babelHelpers: 'bundled', @@ -98,64 +102,6 @@ function createCommonJSConfig(input, output) { } } -function createUMDConfig(input, output, env) { - let name = 'valtio' - const fileName = output.slice('dist/umd/'.length) - const capitalize = (s) => s.slice(0, 1).toUpperCase() + s.slice(1) - if (fileName !== 'index') { - name += fileName.replace(/(\w+)\W*/g, (_, p) => capitalize(p)) - } - return { - input, - output: { - file: `${output}.${env}.js`, - format: 'umd', - name, - globals: { - react: 'React', - 'valtio/vanilla': 'valtioVanilla', - 'valtio/utils': 'valtioUtils', - 'valtio/react': 'valtioReact', - 'valtio/vanilla/utils': 'valtioVanillaUtils', - 'valtio/react/utils': 'valtioReactUtils', - }, - }, - external, - plugins: [ - alias({ entries: entries.filter((e) => !e.find.test(input)) }), - resolve({ extensions }), - replace({ - 'import.meta.env?.MODE': JSON.stringify(env), - delimiters: ['\\b', '\\b(?!(\\.|/))'], - preventAssignment: true, - }), - babelPlugin(getBabelOptions({ ie: 11 })), - ...(env === 'production' ? [terser()] : []), - ], - } -} - -function createSystemConfig(input, output, env) { - return { - input, - output: { - file: `${output}.${env}.js`, - format: 'system', - }, - external, - plugins: [ - alias({ entries: entries.filter((e) => !e.find.test(input)) }), - resolve({ extensions }), - replace({ - 'import.meta.env?.MODE': JSON.stringify(env), - delimiters: ['\\b', '\\b(?!(\\.|/))'], - preventAssignment: true, - }), - getEsbuild('node12', env), - ], - } -} - module.exports = function (args) { let c = Object.keys(args).find((key) => key.startsWith('config-')) if (c) { @@ -167,10 +113,6 @@ module.exports = function (args) { ...(c === 'index' ? [createDeclarationConfig(`src/${c}.ts`, 'dist')] : []), createCommonJSConfig(`src/${c}.ts`, `dist/${c}`), createESMConfig(`src/${c}.ts`, `dist/esm/${c}.mjs`), - createUMDConfig(`src/${c}.ts`, `dist/umd/${c}`, 'development'), - createUMDConfig(`src/${c}.ts`, `dist/umd/${c}`, 'production'), - createSystemConfig(`src/${c}.ts`, `dist/system/${c}`, 'development'), - createSystemConfig(`src/${c}.ts`, `dist/system/${c}`, 'production'), ] }