Skip to content

Commit

Permalink
Initial work on using esbuild
Browse files Browse the repository at this point in the history
  • Loading branch information
lindskogen committed Mar 30, 2021
1 parent 4462647 commit 4a23d3e
Show file tree
Hide file tree
Showing 4 changed files with 10,897 additions and 76 deletions.
42 changes: 42 additions & 0 deletions build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const fsPromises = require('fs/promises')

const esbuild = require('esbuild')

const createBuild = ({ format, env, minify = false }) => {
return esbuild.build({
entryPoints: ['src/index.ts'],
bundle: true,
minify,
format,
sourcemap: 'external',
define: {
'process.env.NODE_ENV': JSON.stringify(env)
},
outfile: `dist/redux-toolkit.${format}.${env}${minify ? '.min' : ''}.js`
})
}

Promise.all([
createBuild({ format: 'esm', env: 'production', minify: true }),
createBuild({ format: 'esm', env: 'development', minify: false }),
createBuild({ format: 'cjs', env: 'production', minify: true }),
createBuild({ format: 'cjs', env: 'development', minify: false }),
createBuild({ format: 'iife', env: 'production', minify: true }),
createBuild({ format: 'iife', env: 'development', minify: false })
]).then(
() => {
return fsPromises.writeFile(
'dist/index.js',
`
'use strict'
if (process.env.NODE_ENV === 'production') {
module.exports = require('./redux-toolkit.cjs.production.min.js')
} else {
module.exports = require('./redux-toolkit.cjs.development.js')
}
`
)
},
() => process.exit(1)
)

0 comments on commit 4a23d3e

Please sign in to comment.