diff --git a/package-lock.json b/package-lock.json index 8960058236..a2dbc595c8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2819,6 +2819,11 @@ "is-symbol": "^1.0.2" } }, + "esbuild": { + "version": "0.10.2", + "resolved": "https://bnpm.byted.org/esbuild/-/esbuild-0.10.2.tgz", + "integrity": "sha1-yqZajzCW1UfYkVmRgDnfbFxskL4=" + }, "escape-string-regexp": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", diff --git a/package.json b/package.json index 9ce6565593..f9456ba621 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "scripts": { "build-ci": "tsdx build --format cjs,esm,system,umd --name redux-toolkit && api-extractor run", "build": "tsdx build --format cjs,esm,system,umd --name redux-toolkit && api-extractor run --local", + "bundle": "node scripts/build.js && tsc && api-extractor run --local", "dev": "tsdx watch --format cjs,esm,system,umd", "format": "prettier --write \"src/**/*.ts\" \"**/*.md\"", "format:check": "prettier --list-different \"src/**/*.ts\" \"docs/*/**.md\"", @@ -61,6 +62,7 @@ "src" ], "dependencies": { + "esbuild": "0.10.2", "immer": "^8.0.1", "redux": "^4.0.0", "redux-thunk": "^2.3.0", @@ -78,4 +80,4 @@ } } } -} +} \ No newline at end of file diff --git a/scripts/build.js b/scripts/build.js new file mode 100644 index 0000000000..bcfed513c9 --- /dev/null +++ b/scripts/build.js @@ -0,0 +1,44 @@ +const { build } = require('esbuild') + +async function bundle(env, format) { + console.log('env:', env) + build({ + entryPoints: ['src/index.ts'], + outfile: `dist/redux-toolkit.${format}.${ + env === 'production' ? 'production.' : '' + }js`, + target: 'es2015', + minify: env === 'production', + sourcemap: true, + bundle: true, + define: { + 'process.env.NODE_ENV': JSON.stringify(env), + }, + plugins: [ + { + name: 'node_module_external', + setup(build) { + build.onResolve({ filter: /.*/ }, (args) => { + if (args.path.startsWith('.') || args.path.startsWith('/')) { + return undefined + } else { + return { + path: args.path, + external: true, + } + } + }) + }, + }, + ], + }) +} +async function main() { + for (const format of ['cjs', 'esm']) { + for (const env of ['development', 'production']) { + bundle(env, format) + } + } +} + +main()