const documentationPlugin = require('./esbuild-documentation-plugin');
const htmlPlugin = require('./esbuild-html-plugin');
const htmlTemplate = require('./indexHtmlTemplate');
-const { getCustomProperties } = require('./utils');
+const { getCustomProperties, TARGET_BROWSERS } = require('./utils');
module.exports = release => {
const plugins = [
minify: release,
metafile: true,
sourcemap: true,
- target: ['chrome58', 'firefox57', 'safari11', 'edge18'],
+ target: TARGET_BROWSERS,
outdir: 'build/webapp/js',
entryNames: release ? 'out[hash]' : 'out',
plugins
return customProperties;
}
+// See https://github.com/evanw/esbuild/issues/337
+function importAsGlobals(mapping) {
+ const escRe = s => s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
+ const filter = new RegExp(
+ Object.keys(mapping)
+ .map(moduleName => `^${escRe(moduleName)}$`)
+ .join('|')
+ );
+
+ return {
+ name: 'import-as-globals',
+ 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'
+ },
+ args => {
+ const globalName = mapping[args.path];
+ return {
+ contents: `module.exports = ${globalName};`,
+ loader: 'js'
+ };
+ }
+ );
+ }
+ };
+}
+
module.exports = {
- getCustomProperties
+ getCustomProperties,
+ importAsGlobals,
+ TARGET_BROWSERS: ['chrome58', 'firefox57', 'safari11', 'edge18']
};