forked from open-wc/open-wc
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodern-config.js
67 lines (60 loc) · 1.85 KB
/
modern-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const resolve = require('rollup-plugin-node-resolve');
const { terser } = require('rollup-plugin-terser');
const babel = require('rollup-plugin-babel');
const minifyHTML = require('rollup-plugin-minify-html-literals').default;
const modernWeb = require('./plugins/rollup-plugin-modern-web/rollup-plugin-modern-web.js');
const production = !process.env.ROLLUP_WATCH;
module.exports = function createBasicConfig(_options) {
const options = {
outputDir: 'dist',
..._options,
};
return {
input: options.input,
treeshake: !!production,
output: {
dir: options.outputDir,
format: 'esm',
sourcemap: true,
},
plugins: [
// minify html and css template literals if in production
production &&
minifyHTML({
failOnError: true,
}),
// parse input index.html as input and feed any modules found to rollup
modernWeb(),
// resolve bare import specifiers
resolve(),
// run code through babel
babel({
plugins: [
'@babel/plugin-syntax-dynamic-import',
'@babel/plugin-syntax-import-meta',
// rollup rewrites import.meta.url, but makes them point to the file location after bundling
// we want the location before bundling
'bundled-import-meta',
],
presets: [
[
'@babel/env',
{
targets: [
'last 2 Chrome major versions',
'last 2 ChromeAndroid major versions',
'last 2 Edge major versions',
'last 2 Firefox major versions',
'last 2 Safari major versions',
'last 2 iOS major versions',
],
useBuiltIns: false,
},
],
],
}),
// only minify if in production
production && terser(),
],
};
};