forked from klembot/chapbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.editor-extensions.js
63 lines (58 loc) · 1.63 KB
/
rollup.config.editor-extensions.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
import 'dotenv/config';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import html from '@rollup/plugin-html';
import image from '@rollup/plugin-image';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import {nodeResolve} from '@rollup/plugin-node-resolve';
import postcss from 'rollup-plugin-postcss';
import pug from 'pug';
import replace from '@rollup/plugin-replace';
import serve from 'rollup-plugin-serve';
import {terser} from 'rollup-plugin-terser';
const isRelease = process.env.NODE_ENV === 'production';
// We use ___format as a placeholder for the `this` that the IIFE we bundle will
// be bound to. See src/editor-extensions/hydrate.js for where this is done.
const config = {
external: ['___format'],
input: isRelease
? 'src/editor-extensions/hydrate.js'
: 'src/editor-extensions/dev.js',
output: {
file: `dist/editor-extensions/index.js`,
format: 'iife',
globals: {
___format: 'this'
},
sourcemap: false
},
plugins: [
commonjs(),
babel({
babelHelpers: 'bundled',
exclude: 'node_modules/**',
presets: [['@babel/env', {modules: false}]]
}),
image(),
nodePolyfills(),
nodeResolve({extensions: ['.js', '.svg']}),
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
}
})
]
};
if (isRelease) {
config.plugins.push(terser());
} else {
config.plugins.push(postcss());
config.plugins.push(
html({template: pug.compileFile('src/editor-extensions/dev.pug')})
);
config.plugins.push(
serve({contentBase: 'dist/editor-extensions', open: true, port: 8080})
);
}
module.exports = config;