forked from opendatasoft/ods-dataviz-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
121 lines (114 loc) · 3.4 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
import svelte from 'rollup-plugin-svelte';
import autoPreprocess from 'svelte-preprocess';
import postcss from 'rollup-plugin-postcss';
import autoprefixer from 'autoprefixer';
import visualizer from 'rollup-plugin-visualizer';
import { terser } from 'rollup-plugin-terser';
import typescript from '@rollup/plugin-typescript';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import { babel } from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import { defineConfig } from 'rollup';
import pkg from './package.json';
const production = !process.env.ROLLUP_WATCH;
function basePlugins() {
return [
svelte({
// enable run-time checks when not in production
dev: !production,
include: 'src/**/*.svelte',
emitCss: true,
immutable: true,
preprocess: autoPreprocess({
scss: {
includePaths: ['src'],
},
}),
}),
typescript({
sourceMap: true,
declaration: true,
declarationDir: 'dist',
rootDir: 'src',
}),
nodeResolve(),
commonjs(),
json(),
postcss({
extract: 'index.css',
plugins: [autoprefixer()],
}),
// Transpile to ES5 when running a production build
production &&
babel({
babelHelpers: 'bundled',
extensions: ['.ts', '.mjs', '.js', '.svelte'],
include: ['src/**', 'node_modules/chart.js/**', 'node_modules/svelte/**'],
presets: ['@babel/preset-env'],
}),
];
}
function onwarn(warning, warn) {
// https://github.com/moment/luxon/issues/193
if (warning.code === 'CIRCULAR_DEPENDENCY') {
if (warning.importer.includes('node_modules/luxon')) {
return;
}
}
warn(warning);
}
const esm = defineConfig({
input: 'src/index.ts',
// Externalize all dependencies
external: (id) => Object.keys(pkg.dependencies).includes(id),
output: {
dir: 'dist',
entryFileNames: '[name].es.js',
format: 'es',
sourcemap: true,
},
plugins: [
...basePlugins(),
// Visualize the generated bundle
production &&
visualizer({
filename: `gen/stats-es.html`,
sourcemap: true,
}),
],
onwarn,
});
const umd = defineConfig({
input: 'src/index.ts',
output: {
dir: 'dist',
entryFileNames: '[name].umd.js',
format: 'umd',
sourcemap: true,
name: 'opendatasoft.visualizations',
plugins: [],
},
plugins: [
...basePlugins(),
// Minify umd bundle
terser(),
// Replace process.env.NODE_ENV with 'production'
production &&
replace({
values: { 'process.env.NODE_ENV': JSON.stringify('production') },
preventAssignment: true,
}),
// Visualize the generated bundle
production &&
visualizer({
filename: 'gen/stats-umd.html',
sourcemap: true,
}),
],
onwarn,
});
// Just compile the ESM version during development
const bundles = production ? [esm, umd] : [esm];
export default bundles;