@cley_faye/boilerplate 4.1.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/lib/grunt/reactapp/webpack.d.ts +1 -0
- package/lib/grunt/reactapp/webpack.js +30 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -148,6 +148,7 @@ The webpack options support a host of properties:
|
|
|
148
148
|
- options: passed as-is to grunt-webpack
|
|
149
149
|
- entry: list of entrypoints. Defaults to using a single entrypoint named
|
|
150
150
|
`webres/<targetname>/js/loader.js`.
|
|
151
|
+
- worker: list of worker entrypoints.
|
|
151
152
|
- externals: record describing external dependencies (dependencies that will not be bundled in the
|
|
152
153
|
bundle).
|
|
153
154
|
Key are the "require" name, value is the variable that will have to exist at runtime.
|
|
@@ -21,6 +21,7 @@ export interface WebpackOptions extends BaseOptions {
|
|
|
21
21
|
mode?: "development" | "production" | "none";
|
|
22
22
|
options?: Record<string, unknown>;
|
|
23
23
|
entry?: Record<string, string>;
|
|
24
|
+
worker?: Record<string, string>;
|
|
24
25
|
externals?: Record<string, string>;
|
|
25
26
|
output?: {
|
|
26
27
|
path?: string;
|
|
@@ -134,18 +134,24 @@ const webpackLoadersDefault = (options) => {
|
|
|
134
134
|
exports.webpackLoadersDefault = webpackLoadersDefault;
|
|
135
135
|
const computeWebpackOutput = (webpackOptions, targetName) => webpackOptions.output ?? {
|
|
136
136
|
chunkFilename: "[name]-[fullhash].js",
|
|
137
|
-
chunkFormat: "module",
|
|
138
137
|
filename: "[name].js",
|
|
139
|
-
module: true,
|
|
140
138
|
path: (0, path_1.resolve)("dist", targetName, "js"),
|
|
141
139
|
};
|
|
142
140
|
const lastNamePosition = 2;
|
|
143
141
|
const getHandledFiles = (webpackEntry) => Object.keys(webpackEntry).reduce((acc, cur) => {
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
const value = webpackEntry[cur];
|
|
143
|
+
const importName = typeof value === "string" ? value : value.import;
|
|
144
|
+
if (importName.startsWith("webres")) {
|
|
145
|
+
const split = importName.split("/");
|
|
146
146
|
acc.push(split.slice(lastNamePosition).join("/"));
|
|
147
147
|
}
|
|
148
|
-
|
|
148
|
+
const goodPath = (0, path_1.resolve)(importName);
|
|
149
|
+
if (typeof webpackEntry[cur] === "string") {
|
|
150
|
+
webpackEntry[cur] = goodPath;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
webpackEntry[cur].import = goodPath;
|
|
154
|
+
}
|
|
149
155
|
return acc;
|
|
150
156
|
}, []);
|
|
151
157
|
const getOutputToWatch = (webpackOptions, targetName) => {
|
|
@@ -194,6 +200,24 @@ const getWebpackPlugins = (webpackOptions) => {
|
|
|
194
200
|
}
|
|
195
201
|
return plugins;
|
|
196
202
|
};
|
|
203
|
+
const getWebpackEntry = (targetName, entries, workers) => {
|
|
204
|
+
if (!entries && !workers)
|
|
205
|
+
return { [targetName]: (0, path_1.join)("webres", targetName, "js", "loader.js") };
|
|
206
|
+
const res = {};
|
|
207
|
+
if (entries) {
|
|
208
|
+
for (const [key, value] of Object.entries(entries))
|
|
209
|
+
res[key] = value;
|
|
210
|
+
}
|
|
211
|
+
if (workers) {
|
|
212
|
+
for (const [key, value] of Object.entries(workers)) {
|
|
213
|
+
res[key] = {
|
|
214
|
+
import: value,
|
|
215
|
+
chunkLoading: "import-scripts",
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return res;
|
|
220
|
+
};
|
|
197
221
|
/** Add a webpack task for the reactApp recipe
|
|
198
222
|
*
|
|
199
223
|
* @param gruntConfig - Grunt configuration to add the task to
|
|
@@ -207,9 +231,7 @@ const getWebpackPlugins = (webpackOptions) => {
|
|
|
207
231
|
* This function add "webpack:<targetName>".
|
|
208
232
|
*/
|
|
209
233
|
const handle = (gruntConfig, targetName, webpackOptions) => {
|
|
210
|
-
const webpackEntry = webpackOptions.entry
|
|
211
|
-
[targetName]: (0, path_1.join)("webres", targetName, "js", "loader.js"),
|
|
212
|
-
};
|
|
234
|
+
const webpackEntry = getWebpackEntry(targetName, webpackOptions.entry, webpackOptions.worker);
|
|
213
235
|
const handledFiles = getHandledFiles(webpackEntry);
|
|
214
236
|
const webpackOutput = computeWebpackOutput(webpackOptions, targetName);
|
|
215
237
|
const webpackLoaders = webpackOptions.loaders ??
|
|
@@ -223,9 +245,6 @@ const handle = (gruntConfig, targetName, webpackOptions) => {
|
|
|
223
245
|
const webpackConfig = {
|
|
224
246
|
devtool: webpackOptions.mode === "development" ? "eval-source-map" : false,
|
|
225
247
|
entry: webpackEntry,
|
|
226
|
-
experiments: {
|
|
227
|
-
outputModule: true,
|
|
228
|
-
},
|
|
229
248
|
externals: webpackOptions.externals,
|
|
230
249
|
mode: webpackOptions.mode,
|
|
231
250
|
module: {
|