forked from zendesk/copenhagen_theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
107 lines (103 loc) · 3.19 KB
/
rollup.config.mjs
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
/* eslint-env node */
import zass from './zass.mjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import dynamicImportVars from '@rollup/plugin-dynamic-import-vars';
import typescript from '@rollup/plugin-typescript';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
import svgr from '@svgr/rollup';
import { generateImportMap } from './generate-import-map.mjs';
import { defineConfig } from 'rollup';
import sass from 'rollup-plugin-sass';
const fileNames = '[name]-bundle.js';
const isProduction = process.env.NODE_ENV === 'production';
const TRANSLATION_FILE_REGEX = /src\/modules\/(.+?)\/translations\/locales\/.+?\.json$/;
export default defineConfig([
// Configuration for bundling the script.js file
{
input: 'src/index.js',
output: {
file: 'script.js',
format: 'iife',
},
plugins: [zass()],
watch: {
clearScreen: false,
},
},
// Configuration for bundling modules in the src/modules directory
{
context: 'this',
input: {
'new-request-form': 'src/modules/new-request-form/index.tsx',
'flash-notifications': 'src/modules/flash-notifications/index.ts',
navigation: 'src/modules/navigation/index.ts',
footer: 'src/modules/footer/index.ts',
homepage: 'src/modules/homepage/index.ts',
'article-page': 'src/modules/article-page/index.ts',
'category-page': 'src/modules/category-page/index.ts',
'section-page': 'src/modules/section-page/index.ts',
'side-nav': 'src/modules/side-nav/index.ts',
"search-result-page": "src/modules/search-result-page/index.ts",
},
output: {
dir: 'assets',
format: 'es',
manualChunks: (id) => {
if (
id.includes('node_modules/@zendesk/help-center-wysiwyg') ||
id.includes('node_modules/@ckeditor5')
) {
return 'wysiwyg';
}
if (id.includes('node_modules') || id.includes('src/modules/shared')) {
return 'shared';
}
// Bundle all files from `src/modules/MODULE_NAME/translations/locales/*.json to `${MODULE_NAME}-translations.js`
const translationFileMatch = id.match(TRANSLATION_FILE_REGEX);
if (translationFileMatch) {
return `${translationFileMatch[1]}-translations`;
}
},
entryFileNames: fileNames,
chunkFileNames: fileNames,
},
plugins: [
nodeResolve({
extensions: ['.js'],
}),
commonjs(),
typescript(),
replace({
preventAssignment: true,
'process.env.NODE_ENV': '"production"',
}),
svgr({
svgo: true,
svgoConfig: {
plugins: [
{
name: 'preset-default',
params: {
overrides: {
removeTitle: false,
convertPathData: false,
removeViewBox: false,
},
},
},
],
},
}),
json(),
dynamicImportVars(),
isProduction && terser(),
generateImportMap(),
],
watch: {
clearScreen: false,
},
},
]);