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) {
|
|
|
|
build.onResolve({ filter: /^react(-dom)?$/ }, (args) => {
|
|
|
|
return {
|
|
|
|
path: args.path,
|
|
|
|
namespace: `globalExternal_${args.path}`,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
build.onLoad(
|
|
|
|
{ filter: /.*/, namespace: 'globalExternal_react' },
|
|
|
|
() => {
|
|
|
|
return {
|
|
|
|
contents: `module.exports = globalThis.React`,
|
|
|
|
loader: 'js',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
build.onLoad(
|
|
|
|
{ filter: /.*/, namespace: 'globalExternal_react-dom' },
|
|
|
|
() => {
|
|
|
|
return {
|
|
|
|
contents: `module.exports = globalThis.ReactDOM`,
|
|
|
|
loader: 'js',
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2022-01-17 19:50:14 +01:00
|
|
|
esbuild
|
|
|
|
.build({
|
|
|
|
entryPoints: [
|
|
|
|
'sidebar/sidebar.tsx',
|
|
|
|
'test.ts',
|
|
|
|
'report-window/report-window.tsx',
|
|
|
|
'background.ts',
|
|
|
|
],
|
|
|
|
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-01-29 21:16:53 +01:00
|
|
|
external: ['react', 'react-dom'],
|
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));
|