-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
112 lines (105 loc) · 2.69 KB
/
rollup.config.mjs
File metadata and controls
112 lines (105 loc) · 2.69 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
111
112
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import { config } from 'dotenv';
import { parseArgs } from 'node:util';
import injectProcessEnv from 'rollup-plugin-inject-process-env';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import postcss from 'rollup-plugin-postcss';
import tsConfigPaths from 'rollup-plugin-tsconfig-paths';
import { visualizer } from 'rollup-plugin-visualizer';
const args = parseArgs({
options: {
environment: {
type: 'string',
short: 'e',
default: 'development',
},
configuration: {
type: 'string',
short: 'c',
},
},
});
const env = args.values.environment;
const production = env === 'production';
let environmentVariablesPath = './.env.development';
console.log(`Building widget for ${env} environment...`);
if (production) {
environmentVariablesPath = './.env.production';
}
const ENV_VARIABLES = config({
path: environmentVariablesPath,
}).parsed;
const fileName = ENV_VARIABLES.WIDGET_NAME || 'widget.js';
export default {
input: './src/index.tsx',
output: {
file: `dist/${fileName}`,
format: 'iife',
sourcemap: false,
inlineDynamicImports: true,
globals: {
'react/jsx-runtime': 'jsxRuntime',
'react-dom/client': 'ReactDOM',
react: 'React',
},
},
plugins: [
tsConfigPaths({
tsConfigPath: './tsconfig.json',
}),
replace({ preventAssignment: true }),
typescript({
tsconfig: './tsconfig.json',
}),
nodeResolve({
extensions: ['.tsx', '.ts', '.json', '.js', '.jsx', '.mjs'],
browser: true,
dedupe: ['react', 'react-dom'],
}),
babel({
babelHelpers: 'bundled',
presets: [
'@babel/preset-typescript',
[
'@babel/preset-react',
{
runtime: 'automatic',
targets: '>0.1%, not dead, not op_mini all',
},
],
],
extensions: ['.js', '.jsx', '.ts', '.tsx', '.mjs'],
}),
postcss({
extensions: ['.css'],
minimize: true,
extract: true,
inject: {
insertAt: 'top',
},
}),
commonjs(),
nodePolyfills({
exclude: ['crypto'],
}),
injectProcessEnv(ENV_VARIABLES),
terser({
ecma: 2020,
mangle: { toplevel: true },
compress: {
module: true,
toplevel: true,
unsafe_arrows: true,
drop_console: true,
drop_debugger: true,
},
output: { quote_style: 1 },
}),
visualizer(),
],
};