-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
bundle.config.mjs
232 lines (207 loc) · 7.75 KB
/
bundle.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
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/**
* config for scripts/bundle.js
*/
import path from "path";
import fs from "fs-extra";
import webpack from "webpack";
import _ from "lodash";
import VirtualModulesPlugin from "webpack-virtual-modules";
import { getUploadyVersion } from "./scripts/uploadyVersion.mjs"
const PKGS = {
LIFE_EVENTS: "@life-events",
SHARED: "@shared",
SENDER: "@sender",
UPLOADER: "@uploader",
SHARED_UI: "@shared-ui",
UPLOADY: "@uploady",
CHUNKED_UPLOADY: "@chunked-uploady",
};
let licenseContent;
export default {
org: "@rpldy/",
version: getUploadyVersion(),
library: "rpldy",
targets: {
umd: "umd",
},
bundles: {
umd: {
/**
* Bundle the core functionality (no UI)
*/
"core": {
pkgs: [PKGS.LIFE_EVENTS, PKGS.SHARED, PKGS.SENDER, PKGS.UPLOADER],
target: PKGS.UPLOADER,
maxSize: 12000,
dontUsePolyfills: true,
},
/**
* Bundle the core functionality + core UI
*/
"ui-core": {
pkgs: ["core", PKGS.SHARED_UI, PKGS.UPLOADY],
target: PKGS.UPLOADY,
config: {
externals: ["react", "react-dom"],
},
maxSize: 15000,
},
/**
* Bundle the core functionality + core UI + Chunked Uploady
*/
"ui-core-chunked": {
pkgs: ["ui-core", PKGS.CHUNKED_UPLOADY],
target: PKGS.CHUNKED_UPLOADY,
config: {
externals: ["react", "react-dom"],
},
maxSize: 17500,
},
/**
* Bundle the entire repo's functionality
*/
"all": {
pkgs: "*",
exclude: ["native-uploady"],
target: PKGS.UPLOADY,
config: (entries) => {
const exports = entries.map((entry) => {
const namespace = _.camelCase(entry.name.split("/")[1]);
return `import * as ${namespace} from "${entry.location}/src/index"; export { ${namespace} };`;
});
return {
output: {
library: "rpldy",
//["rpldy", "[name]"],
},
entry: "./packages/ui/uploady/all-bundle-entry.js",
plugins: [
new VirtualModulesPlugin({
"./packages/ui/uploady/all.generated.js": `${exports.join(" \r\n")}`
})
],
externals: ["react", "react-dom"],
optimization: {
splitChunks: {
cacheGroups: {
commons: {
filename: "[name]-all-bundle.js",
}
}
}
},
};
},
maxSize: 25000,
},
//TODO: find a way to make this work with global object assignment (wepackages/tus-sender/src/tusSender/initTusUpload/createUpload.js:88:94bpack externals root)
//
// /**
// * Bundle a umd bundle per repo package, without internal dependencies
// */
// "package": {
// pkgs: "*",
// target: "*", //output relative to package
// bundlePattern: `*(-runtime)?(\.min)?\\.js`,
// extraBundles: ["polyfills-bundle.js"],
// config: (entries, isProduction) => {
// const entry = entries.reduce((res, pkg) => {
// res[pkg.name.split("/")[1]] = pkg.location;
// return res;
// }, {});
//
// return {
// entry,
// externals: ["react", "react-dom",
// (context, request, callback) => {
// return /@rpldy/.test(request) ? callback(null, {
// commonjs: request,
// commonjs2: request,
// amd: request,
// root: request,
// }) : callback();
// //[`commonjs ${request}`, `amd ${request}`]) : callback();
// }
// ],
// output: {
// library: ["rpldy", "[name]"],
// filename: `rpldy.[name]${isProduction ? ".min" : ""}.js`,
// },
// optimization: {
// runtimeChunk: {
// name: "package-runtime",
// }
// },
// };
// }
// },
},
},
webpackConfig: {
base: {
mode: "development",
devtool: "source-map",
resolve: {
mainFields: ["main:dev", "module", "main"],
},
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: "polyfills",
filename: "[name]-bundle.js",
chunks: "all",
minSize: 0,
}
}
}
},
module: {
rules: [
{
test: /\.?js$/,
exclude: /node_module/,
use: {
loader: "babel-loader",
options: {
presets: [["@babel/preset-env", {
useBuiltIns: false,
// corejs: 3,
}]],
plugins: [["@babel/plugin-transform-runtime", {
corejs: 3,
"version": "^7.19.6"
}]]
}
}
}
]
},
},
production: {
mode: "production",
devtool: "cheap-module-source-map",
optimization: {
//needed for production build to work with single/shared polyfills bundle
chunkIds: "deterministic",
//needed for production build to work with single/shared polyfills bundle
// namedChunks: true,
// //needed for production build to work with single/shared polyfills bundle
// namedModules: true,
//"total-size" is slightly smaller but requires that each bundle relies on its own polyfill bundle and cannot share
moduleIds: "hashed",
},
plugins: [
new webpack.BannerPlugin({
banner: () => {
if (!licenseContent) {
licenseContent = fs.readFileSync(path.resolve(process.cwd(), "LICENSE.md"), { encoding: "utf-8" });
}
return licenseContent;
}
}),
],
}
},
};