Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] breaking: drop UMD/SystemJS builds and simplify babel config #822

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 1 addition & 13 deletions .github/workflows/test-multiple-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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/<rootDir>\/src\(.*\)\.ts/<rootDir>\/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/<rootDir>\/src\(.*\)\.ts/<rootDir>\/dist\/system\1.${NODE_ENV}.js/" package.json
env:
NODE_ENV: ${{ matrix.env }}
- name: Test ${{ matrix.build }} ${{ matrix.env }}
run: |
yarn test:ci
Expand Down
28 changes: 0 additions & 28 deletions babel.config.js

This file was deleted.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
72 changes: 7 additions & 65 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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',
Expand Down Expand Up @@ -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) {
Expand All @@ -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'),
]
}

Expand Down