2022-01-17 19:50:14 +01:00
|
|
|
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
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-17 19:50:14 +01:00
|
|
|
esbuild
|
|
|
|
.build({
|
|
|
|
entryPoints: [
|
2022-04-13 11:44:59 +02:00
|
|
|
'components/toolbar/toolbar.tsx',
|
|
|
|
'components/sidebar/sidebar.tsx',
|
|
|
|
'components/report-window/report-window.tsx',
|
2022-01-17 19:50:14 +01:00
|
|
|
'background.ts',
|
2022-04-25 20:02:20 +02:00
|
|
|
'styles/global.scss',
|
2022-07-09 10:53:20 +02:00
|
|
|
'styles/fonts.scss',
|
2022-01-17 19:50:14 +01:00
|
|
|
],
|
|
|
|
bundle: true,
|
2022-01-29 18:20:26 +01:00
|
|
|
// minify: true,
|
2022-01-17 19:50:14 +01:00
|
|
|
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-17 19:50:14 +01:00
|
|
|
})
|
2022-01-28 11:33:44 +01:00
|
|
|
.then(() => console.log('Add-on was built'))
|
2022-01-17 19:50:14 +01:00
|
|
|
.catch(() => process.exit(1));
|