-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
76 lines (59 loc) · 1.79 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
import svg from 'rollup-plugin-svg'
import sass from 'rollup-plugin-sass'
import resolve from '@rollup/plugin-node-resolve';
import { terser } from "rollup-plugin-terser";
import commonjs from '@rollup/plugin-commonjs'
import cssnano from 'cssnano';
import postcss from 'postcss';
import indexHTML from 'rollup-plugin-index-html';
const license = require('rollup-plugin-license');
const path = require('path');
const fs = require('fs');
const filePath = path.resolve('LICENSE');
const licenseTxt = fs.readFileSync(filePath, 'utf-8');
function getPlugins(isProd) {
const sassOptions = {output:false};
if(isProd) {
sassOptions.processor = css => postcss([cssnano]).process(css,{from:undefined}).then(result => result.css);
}
let plugins = [
indexHTML(),
resolve(),
commonjs(),
svg(),
sass(sassOptions),
];
if(isProd)
plugins.push(terser());
plugins.push(
license({
banner: {
commentStyle: 'regular',
content:
`<%= pkg.name %> <%= pkg.version %> [<%= pkg.homepage %>]
${licenseTxt}
============================ Dependencies ==============================
<% _.forEach(dependencies, function (dependency) { %>
<%= dependency.name %> <%= dependency.version %> [<%= dependency.homepage %>]
<%= dependency.licenseText %>
---------------------------------------------------------------------------
<% }) %>`,
}
},
));
return plugins;
}
const config = {
input: './src/index.html',
output: {
//file:'dist/webapp-menu.js',
dir: 'dist',
format: 'esm',
sourcemap: true,
},
};
export default (args)=>{
const isProduction = !! args.configProduction;
config.plugins = getPlugins(isProduction);
return config;
}