-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
110 lines (100 loc) · 3.04 KB
/
Copy pathrollup.config.js
File metadata and controls
110 lines (100 loc) · 3.04 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import fs from 'fs';
import path from 'path';
import buble from 'rollup-plugin-buble';
import commonjs from 'rollup-plugin-commonjs';
import css from 'rollup-plugin-css-only';
import csso from 'csso';
import hash from 'rollup-plugin-hash';
import hasha from 'hasha';
import nodeResolve from 'rollup-plugin-node-resolve';
import stylus from 'rollup-plugin-stylus-compiler';
import { terser } from 'rollup-plugin-terser';
let root_dir = __dirname
, assets_dir = path.join(root_dir, 'rapperswil_jona', 'assets')
, static_dir = path.join(root_dir, 'static')
, inputs = []
;
if (process.env.NODE_ENV === 'production') {
let manifestJSON = path.join(static_dir, 'manifest.json');
let hashaOptions = {
algorithm: 'sha1'
, replace: false
};
inputs = [{
input: path.join(assets_dir, 'index.js')
, output: [{
file: path.join(static_dir, 'index.min.js')
, format: 'iife'
, sourcemap: false
, globals: ['fontfaceobserver']
}]
, plugins: [
nodeResolve({jsnext: true, module: true})
, stylus()
, css({
output: function(styles, styleNodes) {
fs.writeFileSync(
path.join(static_dir, 'index.min.css')
, csso.minify(styles).css
);
}
})
, buble()
, commonjs()
, terser()
, hash({
...hashaOptions
, manifest: manifestJSON
, manifestKey: 'index.js'
, dest: path.join(static_dir, 'index.min.[hash].js')
, callback: (hashedJsFile) => {
// delete unnecessary js file
let jsFile = path.join(static_dir, 'index.min.js');
fs.unlinkSync(jsFile);
console.log(hashedJsFile);
// update the key in manifest.json
let manifest = fs.readFileSync(manifestJSON);
let contents = JSON.parse(manifest);
delete contents[jsFile];
contents['index.js'] = hashedJsFile;
fs.writeFileSync(manifestJSON, JSON.stringify(contents));
}
})
, {
name: 'hash (css)'
, onwrite: (_bundle, _data) => {
let cssFile = path.join(static_dir, 'index.min.css');
// rename min.css using [hash]
let cssData = fs.readFileSync(cssFile, 'utf8');
let hash = hasha(cssData, hashaOptions);
let hashedCssFile = cssFile.replace(/\.css$/, `.${hash}.css`);
fs.renameSync(cssFile, hashedCssFile);
console.log(hashedCssFile);
// add css entry into manifest.json
let manifest = fs.readFileSync(manifestJSON);
let contents = JSON.parse(manifest);
contents['index.css'] = hashedCssFile;
fs.writeFileSync(manifestJSON, JSON.stringify(contents));
}
}
]
}];
} else {
inputs = [{
input: path.join(assets_dir, 'index.js')
, output: {
file: path.join(static_dir, 'index.js')
, format: 'iife'
, sourcemap: true
, globals: ['fontfaceobserver']
}
, plugins: [
nodeResolve({jsnext: true, module: true})
, stylus()
, css()
, buble()
, commonjs()
]
}];
}
export default inputs