rentgen/esbuild.config.js

68 lines
2.1 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: [
'components/toolbar/toolbar.tsx',
'components/sidebar/sidebar.tsx',
'components/report-window/report-window.tsx',
'background.ts',
2022-04-25 20:02:20 +02:00
'styles/global.scss',
2022-07-09 10:53:20 +02:00
'styles/fonts.scss',
],
bundle: true,
2022-01-29 18:20:26 +01:00
// minify: true,
outdir: './lib',
2022-01-20 19:03:03 +01:00
loader: { '.woff': 'file', '.woff2': '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));