This repository was archived by the owner on Oct 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollup.config.js
205 lines (202 loc) · 5.49 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import path from 'path';
import html2 from 'rollup-plugin-html2';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import alias from '@rollup/plugin-alias';
import { terser } from 'rollup-plugin-terser';
import postcss from 'rollup-plugin-postcss';
import visualizer from 'rollup-plugin-visualizer';
import serve from 'rollup-plugin-serve';
import url from '@rollup/plugin-url';
import strip from '@rollup/plugin-strip';
import cssUrl from 'postcss-url';
import svgo from 'rollup-plugin-svgo';
import manifest from 'rollup-plugin-manifest-json';
import copy from 'rollup-plugin-copy';
import replace from '@rollup/plugin-replace';
import livereload from 'rollup-plugin-livereload';
import imagemin from 'rollup-plugin-imagemin';
import gzip from 'rollup-plugin-gzip';
import cssnano from 'cssnano';
import del from 'rollup-plugin-delete';
const extensions = ['ts', 'tsx', 'js', 'jsx'].map((x) => '.' + x);
const preload = ['solid-js', 'router5', 'serviceWorker'];
const production = process.env.NODE_ENV === 'production';
/** @type {import('rollup').RollupOptions} */
const config = {
input: ['src/index.tsx', 'src/workers/serviceWorker.ts'],
watch: {
clearScreen: true,
exclude: ['node_modules', 'distribution'],
},
preserveEntrySignatures: false,
treeshake: production,
output: {
sourcemap: !production ? 'inline' : false,
dir: 'dist',
format: 'es',
chunkFileNames: '[name].[hash].mjs',
entryFileNames: '[name].mjs',
minifyInternalExports: production,
// comment this for Microsoft Edge
manualChunks: (id) => {
const { ext, name: fileName } = path.parse(id);
if (!extensions.includes(ext)) return;
let name = fileName;
if (id.includes('node_modules')) {
const directories = id.split(path.sep);
name = directories[directories.lastIndexOf('node_modules') + 1];
}
const lib = preload.find((x) => name.includes(x));
if (lib) return lib;
// force keep deps in the default chunk.
if (name === 'loadash.throttle') {
return;
}
return;
},
},
plugins: [
nodeResolve({
extensions,
}),
babel({
extensions,
babelHelpers: 'bundled',
presets: [
// use this for Microsoft Edge
// [
// '@babel/preset-env',
// {
// useBuiltIns: 'usage',
// corejs: 3,
// forceAllTransforms: true,
// targets: { browsers: 'last 2 versions' },
// },
// ],
'solid',
'@babel/preset-typescript',
],
// use this for Microsoft Edge
// plugins: [
// '@babel/plugin-syntax-dynamic-import',
// '@babel/proposal-class-properties',
// '@babel/plugin-proposal-object-rest-spread',
// ],
// use use this for Microsoft Edge
// exclude: [
// /(node_modules\/)(?!(solid-js|router5|solid-typefu-router5))/,
// /node_modules\/core-js/,
// ],
exclude: /node_modules\//,
}),
commonjs({
extensions,
}),
replace({
values: {
'process.env.PUBLIC_URL': production ? '"YOUR_SITE_URL"' : '"localhost:3000"',
},
}),
postcss({
modules: {
generateScopedName: production ? '[local][hash:base64:2]' : undefined,
},
minimize: production,
extract: true,
to: path.resolve(__dirname, 'dist', 'assets'),
plugins: [
cssUrl({
filter: /\.(png|jpg|ttf|svg)/,
url: 'copy',
useHash: true,
basePath: '.',
}),
production && cssnano(),
],
}),
url({
limit: 2048,
include: /\.(png|jpg|jpeg|webp|svg)/,
exclude: /\.svg/,
publicPath: '/',
}),
svgo(),
!production &&
serve({
contentBase: './dist',
port: 3000,
historyApiFallback: true,
}),
!production &&
livereload({
watch: './dist',
}),
html2({
template: './src/assets/index.html',
modules: true,
injectCssType: 'style',
preload: preload.map((name) => ({
rel: 'modulepreload',
type: 'script',
name: './' + name,
})),
exclude: ['serviceWorker'],
minify: {
minifyCSS: production,
minifyURLs: production,
removeComments: production,
removeEmptyAttributes: production,
removeTagWhitespace: production,
removeRedundantAttributes: production,
removeAttributeQuotes: production,
minifyJS: production,
},
externals: [],
}),
alias({
entries: [{ find: '@', replacement: path.join(__dirname, 'src') }],
}),
manifest({
input: 'manifest.json',
minify: production,
}),
copy({
flatten: true,
overwrite: true,
targets: [
{
src: './src/assets/images/favorite/*.*',
dest: './dist',
},
],
}),
production &&
strip({
include: /\.(js|mjs|ts|tsx|jsx)/,
}),
production &&
terser({
toplevel: true,
compress: true,
module: true,
format: {
comments: false,
ecma: 2020,
},
}),
production && imagemin(),
production &&
gzip({
filter: /\.(js|mjs|json|css|html|xml)$/,
}),
production &&
visualizer({
open: false,
bundlesRelative: true,
}),
del({ runOnce: true, targets: 'dist/*' }),
],
};
export default config;