rentgen/esbuild.config.js

76 lines
2.3 KiB
JavaScript
Raw Normal View History

import esbuild from 'esbuild';
import scss from 'esbuild-plugin-sass';
2022-01-28 11:33:44 +01:00
const watch = process.argv.includes('--watch') && {
onRebuild(error) {
if (error) console.error('[watch] build failed', error);
else console.log('[watch] build finished');
},
};
2022-01-29 21:16:53 +01:00
// see https://github.com/evanw/esbuild/issues/806#issuecomment-779138268
let skipReactImports = {
name: 'skipReactImports',
setup(build) {
2022-07-09 16:41:22 +02:00
build.onResolve({ filter: /^(react(-dom)?|survey-react)$/ }, (args) => {
2022-01-29 21:16:53 +01:00
return {
path: args.path,
namespace: `globalExternal_${args.path}`,
};
});
2022-07-09 10:53:20 +02:00
build.onLoad({ filter: /.*/, namespace: 'globalExternal_react' }, () => {
return {
contents: `module.exports = globalThis.React`,
loader: 'js',
};
});
2022-01-29 21:16:53 +01:00
2022-07-09 10:53:20 +02:00
build.onLoad({ filter: /.*/, namespace: 'globalExternal_react-dom' }, () => {
return {
contents: `module.exports = globalThis.ReactDOM`,
loader: 'js',
};
});
2022-07-09 16:41:22 +02:00
build.onLoad({ filter: /.*/, namespace: 'globalExternal_survey-react' }, () => {
return {
contents: `module.exports = globalThis.Survey`,
loader: 'js',
};
});
2022-01-29 21:16:53 +01:00
},
};
esbuild
.build({
entryPoints: [
'src/components/toolbar/toolbar.tsx',
'src/components/sidebar/sidebar.tsx',
'src/components/report-window/report-window.tsx',
'src/background.ts',
'src/styles/global.scss',
'src/styles/fonts.scss',
],
bundle: true,
2022-01-29 18:20:26 +01:00
// minify: true,
outdir: './dist',
loader: {
'.woff': 'file',
'.woff2': 'file',
'.eot': 'file',
'.ttf': 'file',
'.svg': 'file',
'.json': 'json',
'.html': 'file',
},
2022-01-29 21:16:53 +01:00
plugins: [scss(), skipReactImports],
2022-01-30 17:36:42 +01:00
define: {
PLUGIN_NAME: '"Rentgen"',
PLUGIN_URL: '"https://git.internet-czas-dzialac.pl/icd/rentgen"',
},
2022-07-09 16:41:22 +02:00
external: ['react', 'react-dom', 'survey-react'],
2022-01-28 11:33:44 +01:00
watch,
})
2022-01-28 11:33:44 +01:00
.then(() => console.log('Add-on was built'))
.catch(() => process.exit(1));