forked from convos-chat/convos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
71 lines (62 loc) · 2.28 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
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import cssnano from 'cssnano';
import postcss from 'rollup-plugin-postcss'
import postcssPresetEnv from 'postcss-preset-env';
import resolve from '@rollup/plugin-node-resolve';
import svelte from 'rollup-plugin-svelte';
import visualizer from 'rollup-plugin-visualizer';
import {eslint} from 'rollup-plugin-eslint';
import {terser} from 'rollup-plugin-terser';
// The html plugin generates a file that M::P::Webpack reads to generate the
// correct output when calling <%= asset 'convos.js' %> and
// <%= asset 'convos.css' %>
import html from 'rollup-plugin-bundle-html';
// The output file need to contain a hash for M::P::Webpack to find it
const dest = process.env.WEBPACK_OUT_DIR || 'public/asset';
const development = process.env.NODE_ENV == 'development' || (process.env.ROLLUP_WATCH ? true : false);
const ts = parseInt((new Date().getTime() / 1000), 10).toString(16);
function outPath(name) {
const filename = name.replace(/\[hash\]/, development ? 'development' : ts);
return [dest, filename].join('/');
}
// Define default plugins
const plugins = [
svelte({dev: development}),
resolve(),
commonjs(),
postcss({extract: true, plugins: [postcssPresetEnv(), cssnano()]}),
];
if (development) plugins.unshift(eslint({exclude: ['assets/sass/**', 'node_modules/**']}));
plugins.push(babel({
//exclude: 'node_modules/**',
extensions: ['.html', '.js', '.mjs', '.svelte'],
presets: [['@babel/preset-env', {corejs: 3, debug: false, useBuiltIns: 'entry'}]],
babelHelpers: 'runtime',
plugins: ['@babel/plugin-transform-runtime'],
}));
if (!development) {
plugins.push(visualizer({filename: 'public/docs/js-modules-visualized.html', title: 'Convos JavaScript modules visualized'}));
plugins.push(terser());
}
plugins.push(html({
dest,
filename: 'webpack.' + (development ? 'development' : 'production') + '.html',
inject: 'head',
template: '<html><head></head><body></body></html>',
}));
// Define config
export default {
input: 'assets/entrypoint.js',
output: {
// The output file need to contain a hash for M::P::Webpack to find it
file: outPath('convos.[hash].js'),
format: 'iife',
name: 'convos',
sourcemap: true,
},
plugins,
watch: {
clearScreen: false,
},
};