mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-10 19:56:54 +03:00
e57bcb3933
* Build @redux-devtools/app UMDs using esbuild * Fix variable being exported * Remove module.hot * Include CSS * Cleanup * Cleanup * Create slow-paws-beg.md
68 lines
1.5 KiB
JavaScript
68 lines
1.5 KiB
JavaScript
import * as esbuild from 'esbuild';
|
|
|
|
const args = process.argv.slice(2);
|
|
const prod = !args.includes('--dev');
|
|
|
|
await esbuild.build({
|
|
bundle: true,
|
|
logLevel: 'info',
|
|
format: 'iife',
|
|
globalName: 'ReduxDevToolsApp',
|
|
outfile: prod ? 'umd/redux-devtools-app.min.js' : 'umd/redux-devtools-app.js',
|
|
minify: prod,
|
|
sourcemap: true,
|
|
define: {
|
|
'process.env.NODE_ENV': prod ? '"production"' : '"development"',
|
|
},
|
|
entryPoints: ['src/index.tsx'],
|
|
loader: {
|
|
'.woff2': 'dataurl',
|
|
},
|
|
plugins: [
|
|
importAsGlobals({
|
|
react: 'React',
|
|
'react-dom': 'ReactDOM',
|
|
}),
|
|
],
|
|
});
|
|
|
|
// https://github.com/evanw/esbuild/issues/337#issuecomment-954633403
|
|
function importAsGlobals(mapping) {
|
|
// https://stackoverflow.com/a/3561711/153718
|
|
const escRe = (s) => s.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
|
|
const filter = new RegExp(
|
|
Object.keys(mapping)
|
|
.map((mod) => `^${escRe(mod)}$`)
|
|
.join('|'),
|
|
);
|
|
|
|
return {
|
|
name: 'global-imports',
|
|
setup(build) {
|
|
build.onResolve({ filter }, (args) => {
|
|
if (!mapping[args.path]) {
|
|
throw new Error('Unknown global: ' + args.path);
|
|
}
|
|
return {
|
|
path: args.path,
|
|
namespace: 'external-global',
|
|
};
|
|
});
|
|
|
|
build.onLoad(
|
|
{
|
|
filter,
|
|
namespace: 'external-global',
|
|
},
|
|
async (args) => {
|
|
const global = mapping[args.path];
|
|
return {
|
|
contents: `module.exports = ${global};`,
|
|
loader: 'js',
|
|
};
|
|
},
|
|
);
|
|
},
|
|
};
|
|
}
|