-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
74 lines (68 loc) · 2.44 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
import process from 'process'
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import url from '@rollup/plugin-url'
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars'
import manifest from 'rollup-plugin-output-manifest'
import styles from 'rollup-plugin-styles'
import { terser } from 'rollup-plugin-terser'
const isProd = (process.env.NODE_ENV == 'production')
const COMPONENT_REGEXP = /components\/([a-z_]+)/
let outputConfig = {
dir: 'trip_planner/static/assets',
assetFileNames: '[name][extname]',
format: 'es',
sourcemap: true
}
if (isProd) {
outputConfig.entryFileNames = '[name]-[hash].js'
outputConfig.assetFileNames = '[name]-[hash][extname]'
}
export default {
input: {
point_form: 'assets/js/point_form.js',
trip_show: 'assets/js/trip_show.js',
trip_form: 'assets/js/trip_form.js',
app: 'assets/js/app.js',
},
output: outputConfig,
manualChunks(id, { getModuleInfo }) {
if (id.includes('node_modules')) {
if (isProd) return 'vendor';
let comp_match = /node_modules(\/@[a-z_]+)?\/([a-z_]+)/.exec(id)
return `node_modules/${comp_match[1] || ''}/${comp_match[2]}`
}
if(id.endsWith('.png') && id.includes('icons')) {
return 'images/icons'
}
let comp_match = COMPONENT_REGEXP.exec(id)
if (comp_match) {
let modinfo = getModuleInfo(id)
if (modinfo.importers.length + modinfo.dynamicImporters.length > 1) {
console.log(`${id} => ${comp_match[1]}`)
return comp_match[1]
}
}
},
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
resolve({ jsnext: true, preferBuiltins: true, browser: true }),
commonjs(),
json(),
styles({ mode: ['extract', 'app.css'], autoModules: true }),
isProd && terser(),
url({limit: 2048, publicPath: '/static/assets/', exclude: ['assets/js/**/icons/*.svg']}),
url({
limit: 0,
fileName: 'icons/[name]-[hash][extname]',
publicPath: '/static/assets/',
include: ['assets/js/**/icons/*.svg']
}),
dynamicImportVars(),
manifest({ nameWithExt: false, publicPath: 'assets/' }),
]
};