2020-03-08 14:01:00 -07:00
|
|
|
|
|
|
|
const { resolve } = require('./resolve');
|
|
|
|
const { rollup } = require('rollup');
|
|
|
|
const alias = require('@rollup/plugin-alias');
|
|
|
|
const commonjs = require('@rollup/plugin-commonjs');
|
|
|
|
const nodeResolve = require('@rollup/plugin-node-resolve');
|
|
|
|
const replace = require('@rollup/plugin-replace');
|
|
|
|
const babel = require('rollup-plugin-babel');
|
|
|
|
const svg = require('rollup-plugin-react-svg');
|
|
|
|
const { terser } = require('rollup-plugin-terser');
|
|
|
|
|
|
|
|
const plugins = [
|
|
|
|
replace({ 'process.env.NODE_ENV': '"production"' }),
|
|
|
|
alias({
|
|
|
|
entries: [
|
|
|
|
{ find: 'react', replacement: 'preact/compat' },
|
|
|
|
{ find: 'react-dom', replacement: 'preact/compat' },
|
|
|
|
{ find: 'svg', replacement: resolve('svg') },
|
|
|
|
{ find: 'utils', replacement: resolve('build/lib/util.js') },
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
svg(),
|
|
|
|
babel({
|
|
|
|
exclude: 'node_modules/**',
|
|
|
|
}),
|
|
|
|
nodeResolve(),
|
2020-04-07 10:29:37 -07:00
|
|
|
extensions: [ '.mjs', '.js', '.jsx', '.json' ],
|
|
|
|
}),
|
2020-03-08 14:01:00 -07:00
|
|
|
commonjs({
|
|
|
|
include: 'node_modules/**',
|
|
|
|
}),
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = exports = async function (input, prod) {
|
|
|
|
const inputOptions = {
|
|
|
|
input,
|
|
|
|
plugins,
|
|
|
|
};
|
|
|
|
|
|
|
|
const outputOptions = {
|
|
|
|
format: 'iife',
|
|
|
|
sourcemap: 'inline',
|
|
|
|
plugins: prod
|
|
|
|
? [ terser({ output: { comments: false } }) ]
|
|
|
|
: undefined,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
const bundle = await rollup(inputOptions);
|
|
|
|
const output = await bundle.generate(outputOptions);
|
|
|
|
|
|
|
|
// console.log(output);
|
|
|
|
return output.output[0].code;
|
|
|
|
};
|