-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
45 lines (42 loc) · 1.19 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
import path from 'path'
import {createHash} from 'crypto'
import {mkdirSync, writeFileSync} from 'fs'
import typescript from '@rollup/plugin-typescript'
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
const hash = {
name: 'hash-name',
async generateBundle(opts, bundles) {
const {sourcemap, file} = opts
opts.sourcemap = false
const dir = path.dirname(file)
mkdirSync(dir, {recursive: true})
for (const filename in bundles) {
const bundle = bundles[filename]
const sha256 = createHash('sha256')
const hash = sha256.update(bundle.code).digest('hex').substr(0, 10)
bundle.fileName = `${bundle.name}-${hash}${path.extname(filename)}`
if (sourcemap) {
const mapFile = `${bundle.name}-${hash}.js.map`
const mapPath = path.join(dir, mapFile)
bundle.code += `//# sourceMappingURL=${mapFile}\n`
writeFileSync(mapPath, bundle.map.toString())
}
}
}
}
export default {
input: 'assets/app.js',
output: {
file: 'public/assets/app.js',
format: 'iife',
sourcemap: true
},
treeshake: true,
plugins: [
typescript(),
resolve(),
commonjs(),
hash
]
}