-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
94 lines (81 loc) · 2.05 KB
/
rollup.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* plugin imports */
import copy from 'rollup-plugin-copy-glob';
import includePaths from 'rollup-plugin-includepaths';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import typescript from '@rollup/plugin-typescript';
/* misc. imports */
import glob from 'glob';
/* global constants */
const IS_DEV_MODE = !process.env.production;
/* config.plugins */
const copyConfig = [
{ files: 'src/**/*.liquid', dest: 'dist' },
{ files: 'src/**/**/*.liquid', dest: 'dist' },
{ files: 'src/config/*.json', dest: 'dist/config' },
{ files: 'src/locales/*.json', dest: 'dist/locales' },
];
const includePathsConfig = {
include: {},
paths: ['src/scripts'],
external: [],
extensions: ['.tsx', '.ts', '.jsx', '.js', '.json', '.html']
}
// Plugins used for all builds
const getBasePlugins = () => [
includePaths(includePathsConfig),
nodeResolve({ browser: true }),
typescript(),
babel({
presets: [
[
'@babel/preset-react',
{
"pragma": "h",
"pragmaFrag": "Fragment",
"throwIfNamespace": false,
"runtime": "classic"
}
]
]
}),
]
/* config.input */
const inputScriptMap = {};
for (const filename of glob.sync('src/scripts/templates/*.js')) {
const bundle = filename.replace('src/scripts/', '').replace('.js', '').replace('/', '.');
inputScriptMap[bundle] = filename;
}
const config = {
input: inputScriptMap,
output: [
// ES module version, for modern browsers
{
dir: 'dist/assets/',
format: 'es',
sourcemap: 'inline' // FIXME: Why does setting this to "true" break things?
},
],
plugins: [
copy(copyConfig),
...getBasePlugins(),
]
}
// Browser support for IE.
const iifeConfigs = [];
if (!IS_DEV_MODE) {
for (const key in inputScriptMap) {
iifeConfigs.push({
input: { [key + '.iife']: inputScriptMap[key] },
output: {
dir: 'dist/assets',
format: 'iife'
},
plugins: getBasePlugins(),
});
}
}
export default [
config,
...iifeConfigs,
]