-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrollup.config.js
145 lines (136 loc) · 4.01 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import svelte from 'rollup-plugin-svelte';
import replace from '@rollup/plugin-replace';
import json from "@rollup/plugin-json";
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import iconifySvg from 'rollup-plugin-iconify-svg';
import { generateSW } from 'rollup-plugin-workbox';
const production = !process.env.ROLLUP_WATCH;
const options = {
onwarn: function (warning) {
if (warning.code === 'THIS_IS_UNDEFINED') {
return;
}
console.error(warning.message);
},
plugins: [
iconifySvg({
targets: [{ src: 'src/components/views', dest: 'src/components/tools/icons.js' }]
}),
svelte({
// enable run-time checks when not in production
dev: !production,
// we'll extract any component CSS out into
// a separate file — better for performance
css: css => {
css.write('bundle.css');
}
}),
replace({
// you're right, you shouldn't be injecting this
// into a client script :)
__AB_THRESHOLD__: process.env.AB_THRESHOLD,
__API_EMAIL__: process.env.API_EMAIL,
__API_MAX_BODY__: process.env.API_MAX_BODY,
__ES_PROXY_PATH__: process.env.ES_PROXY_PATH,
__ES_MAX_RESULTS__: process.env.ES_MAX_RESULTS,
__BACKEND_TOKEN_USER__: process.env.BACKEND_TOKEN_USER,
__BACKEND_PROXY_PATH__: process.env.BACKEND_PROXY_PATH,
__DATAGOUV_PROXY_PATH__ : process.env.DATAGOUV_PROXY_PATH,
__DATAGOUV_CATALOG_URL__: process.env.DATAGOUV_CATALOG_URL,
__DATAGOUV_RESOURCES_URL__: process.env.DATAGOUV_RESOURCES_URL,
__MITM_URL__: process.env.MITM_URL,
__APP__: process.env.APP,
__APP_VERSION__: process.env.APP_VERSION,
__THEME_DNUM__: process.env.THEME_DNUM
}),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration —
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true,
dedupe: importee => importee === 'svelte' || importee.startsWith('svelte/')
}),
commonjs(),
json(),
// In dev mode, call `npm run start` once
// the bundle has been generated
!production && serve(),
// Watch the `public` directory and refresh the
// browser on changes when not in production
!production && livereload({ watch: "public", delay: 1000 }),
// If we're building for production (npm run build
// instead of npm run dev), minify
generateSW({
swDest: 'public/sw.js',
cleanupOutdatedCaches: true,
globDirectory: 'public/',
navigateFallback: '/index.html',
globIgnores: [ '{Geo,LinkCheck,Line,Bar}-*.js'],
globPatterns: [
'index.html',
'build/module/main.js',
'manifest.json',
'build/module/{main,Link,Default}-*.js',
'favicon*{png,svg}',
'{male,female}.svg',
'fonts/Marianne-{Bold,Regular}.woff2',
'css/{global,dsfr.min}.css',
'build/module/bundle.css'
],
navigateFallbackDenylist: [
new RegExp(`${process.env.BACKEND_PROXY_PATH}.*`),
new RegExp(`${process.env.DATAGOUV_PROXY_PATH}.*`)
]
}),
production && terser()
],
watch: {
clearScreen: false,
exclude:['src/components/tools/icons.js']
}
};
const targets = [
// ES module version, for modern browsers
{
input: 'src/main.js',
output: {
sourcemap: true,
format: 'es',
name: 'app',
dir: 'public/build/module'
},
...options
},
// No module version for legacy browsers like Firefox 52.9 esr
{
input: 'src/main.js',
output: {
sourcemap: true,
format: 'iife',
inlineDynamicImports: true,
name: 'app',
dir: 'public/build/nomodule'
},
...options
}
];
export default production ? [targets[0], targets[1]] : [targets[0]];
function serve() {
let started = false;
return {
writeBundle() {
if (!started) {
started = true;
require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
}
}
};
}