forked from GoogleChrome/developer.chrome.com
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
78 lines (72 loc) · 2.03 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
// A Rollup plugin which locates modules using the Node resolution algorithm,
// for using third party modules in node_modules
import {nodeResolve} from '@rollup/plugin-node-resolve';
// A Rollup plugin to convert CommonJS modules to ES6, so they can be included
// in a Rollup bundle
import commonjs from '@rollup/plugin-commonjs';
import svg from 'rollup-plugin-svg';
// A Rollup plugin to minify generated ES bundles. Uses terser under the hood.
import {terser} from 'rollup-plugin-terser';
// A Rollup plugin for copying files.
import copy from 'rollup-plugin-copy';
const devConfig = {
input: 'site/_js/main.js',
output: {
dir: 'dist/js',
format: 'esm',
},
watch: {
// By default rollup clears the console on every build. This disables that.
clearScreen: false,
},
plugins: [
nodeResolve(),
commonjs(),
svg(),
copy({
// Legacy docs, like those at /docs/native-client/, rely on the old
// prettify.js code for syntax highlighting.
targets: [{src: 'site/_js/prettify.js', dest: 'dist/js'}],
}),
],
};
const productionConfig = {
input: 'site/_js/main.js',
output: {
dir: 'dist/js',
format: 'esm',
},
plugins: [
nodeResolve(),
commonjs(),
svg(),
terser({
format: {
// Remove all comments, including @license comments,
// otherwise LHCI complains at us.
comments: false,
},
}),
copy({
targets: [{src: 'site/_js/prettify.js', dest: 'dist/js'}],
}),
],
};
/**
* Determine which rollup config to return based on the environment.
*
* Note: You can also pass custom command line arguments to rollup if they're
* prefixed with `config*`.
*
* Example: rollup -c --configFoo # sets commandLineArgs.configFoo to true
*
* The commandLineArgs argument gets passed to this function, but we're omitting
* it here because we don't use it.
* Learn more @ https://rollupjs.org/guide/en/
*/
export default () => {
if (process.env.NODE_ENV === 'production') {
return productionConfig;
}
return devConfig;
};