@cley_faye/boilerplate 3.19.0 → 3.21.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/bin/serve_spa.js +20 -4
- package/lib/grunt/reactapp/webpack.d.ts +4 -0
- package/lib/grunt/reactapp/webpack.js +19 -4
- package/package.json +10 -8
package/README.md
CHANGED
|
@@ -166,6 +166,7 @@ The webpack options support a host of properties:
|
|
|
166
166
|
- mode: The build mode. "development", "production" or "none"
|
|
167
167
|
- defines: a record of value to define using Babel transform-define
|
|
168
168
|
- resolve: a custom "resolve" object for webpack config
|
|
169
|
+
- generateReport: a boolean, set to true to generate a bundle size report HTML file
|
|
169
170
|
|
|
170
171
|
### SASS
|
|
171
172
|
All `.sass` and `.scss` files in the `webres` directory will be processed as `.css` files
|
package/lib/bin/serve_spa.js
CHANGED
|
@@ -53,16 +53,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
53
53
|
};
|
|
54
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
55
55
|
const path = __importStar(require("node:path"));
|
|
56
|
+
const node_fs_1 = require("node:fs");
|
|
56
57
|
const express_1 = __importDefault(require("express"));
|
|
57
58
|
const minimist_1 = __importDefault(require("minimist"));
|
|
58
59
|
const singlepageapp_js_1 = require("../express/middlewares/singlepageapp.js");
|
|
59
60
|
const express_js_1 = require("../express.js");
|
|
60
61
|
const winston_js_1 = require("../winston.js");
|
|
61
62
|
const ARGV_START_OFFSET = 2;
|
|
62
|
-
const { port, root, index, help, static: staticDirs } = (0, minimist_1.default)(process.argv.slice(ARGV_START_OFFSET));
|
|
63
|
+
const { port, root, index, help, staticlist, static: staticDirs } = (0, minimist_1.default)(process.argv.slice(ARGV_START_OFFSET));
|
|
63
64
|
const DEFAULT_PORT = 3000;
|
|
64
65
|
const DEFAULT_PATH = path.join("dist", "webapp");
|
|
65
66
|
const DEFAULT_INDEX = "index.html";
|
|
67
|
+
const DEFAULT_STATICFILE = "spa_static.config";
|
|
66
68
|
const DEFAULT_STATIC = ["js", "css", "img"];
|
|
67
69
|
if (help) {
|
|
68
70
|
winston_js_1.consoleLogger.info(`
|
|
@@ -72,20 +74,34 @@ serve_spa \\
|
|
|
72
74
|
[--port=${DEFAULT_PORT}] \\
|
|
73
75
|
[--root=${DEFAULT_PATH}] \\
|
|
74
76
|
[--index=${DEFAULT_INDEX}] \\
|
|
77
|
+
[--staticlist=${DEFAULT_STATICFILE}] \\
|
|
75
78
|
[--static=js…] \\
|
|
76
79
|
[--help]
|
|
77
80
|
|
|
78
81
|
The --static argument can be repeated to add more directories to it.
|
|
79
82
|
It defaults to ${JSON.stringify(DEFAULT_STATIC)}.
|
|
83
|
+
|
|
84
|
+
The staticfile value is a text file with one static directory line.
|
|
85
|
+
If present, they are merged with the CLI arguments.
|
|
80
86
|
`.trim());
|
|
81
87
|
// eslint-disable-next-line no-process-exit
|
|
82
88
|
process.exit(0);
|
|
83
89
|
}
|
|
84
90
|
const getPort = () => port ?? DEFAULT_PORT;
|
|
85
91
|
const getStatic = () => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
92
|
+
const result = [];
|
|
93
|
+
if (staticDirs)
|
|
94
|
+
result.push(...(Array.isArray(staticDirs) ? staticDirs : [staticDirs]));
|
|
95
|
+
if (staticlist) {
|
|
96
|
+
for (const staticsrc of (Array.isArray(staticlist) ? staticlist : [staticlist])) {
|
|
97
|
+
if (!(0, node_fs_1.existsSync)(staticsrc))
|
|
98
|
+
continue;
|
|
99
|
+
result.push(...(0, node_fs_1.readFileSync)(staticsrc, "utf8")
|
|
100
|
+
.split("\n")
|
|
101
|
+
.filter(c => c));
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return result.length > 0 ? result : undefined;
|
|
89
105
|
};
|
|
90
106
|
const app = (0, express_1.default)();
|
|
91
107
|
app.use((0, express_js_1.createPipeline)({
|
|
@@ -52,6 +52,7 @@ export interface WebpackOptions extends BaseOptions {
|
|
|
52
52
|
babelPlugins?: Array<Record<string, unknown>>;
|
|
53
53
|
defines?: Record<string, string>;
|
|
54
54
|
resolve?: ResolveOptions;
|
|
55
|
+
generateReport?: boolean;
|
|
55
56
|
typescript?: boolean;
|
|
56
57
|
}
|
|
57
58
|
/** Add a webpack task for the reactApp recipe
|
|
@@ -106,6 +107,9 @@ export interface WebpackOptions extends BaseOptions {
|
|
|
106
107
|
* Build mode. "development", "production" or "none".
|
|
107
108
|
* Defaults to "development"
|
|
108
109
|
*
|
|
110
|
+
* @param [webpackOptions.generateReport]
|
|
111
|
+
* Generate a bundle report HTML file.
|
|
112
|
+
*
|
|
109
113
|
* @param [webpackOptions.typescript]
|
|
110
114
|
* Allow loading typescript source for webpack/babel.
|
|
111
115
|
*
|
|
@@ -33,6 +33,7 @@ exports.handle = exports.webpackLoadersDefault = void 0;
|
|
|
33
33
|
const path_1 = require("path");
|
|
34
34
|
const node_fs_1 = require("node:fs");
|
|
35
35
|
const eslint_webpack_plugin_1 = __importDefault(require("eslint-webpack-plugin"));
|
|
36
|
+
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
36
37
|
const util_js_1 = require("./util.js");
|
|
37
38
|
const defaultCoreJS = 3;
|
|
38
39
|
const eslintPlugin = () => new eslint_webpack_plugin_1.default({ cache: true });
|
|
@@ -178,6 +179,20 @@ const computeWebpackResolve = (webpackOptions) => {
|
|
|
178
179
|
}
|
|
179
180
|
return res;
|
|
180
181
|
};
|
|
182
|
+
const getWebpackPlugins = (webpackOptions) => {
|
|
183
|
+
const plugins = [
|
|
184
|
+
eslintPlugin(),
|
|
185
|
+
...webpackOptions.plugins ?? [],
|
|
186
|
+
];
|
|
187
|
+
if (webpackOptions.generateReport) {
|
|
188
|
+
plugins.push(new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
|
|
189
|
+
analyzerMode: "static",
|
|
190
|
+
reportFilename: (0, path_1.join)(process.cwd(), "bundle_report.html"),
|
|
191
|
+
openAnalyzer: false,
|
|
192
|
+
}));
|
|
193
|
+
}
|
|
194
|
+
return plugins;
|
|
195
|
+
};
|
|
181
196
|
/** Add a webpack task for the reactApp recipe
|
|
182
197
|
*
|
|
183
198
|
* @param gruntConfig
|
|
@@ -230,6 +245,9 @@ const computeWebpackResolve = (webpackOptions) => {
|
|
|
230
245
|
* Build mode. "development", "production" or "none".
|
|
231
246
|
* Defaults to "development"
|
|
232
247
|
*
|
|
248
|
+
* @param [webpackOptions.generateReport]
|
|
249
|
+
* Generate a bundle report HTML file.
|
|
250
|
+
*
|
|
233
251
|
* @param [webpackOptions.typescript]
|
|
234
252
|
* Allow loading typescript source for webpack/babel.
|
|
235
253
|
*
|
|
@@ -257,10 +275,7 @@ const handle = (gruntConfig, targetName, webpackOptions) => {
|
|
|
257
275
|
output: webpackOutput,
|
|
258
276
|
externals: webpackOptions.externals,
|
|
259
277
|
module: { rules: webpackLoaders },
|
|
260
|
-
plugins:
|
|
261
|
-
eslintPlugin(),
|
|
262
|
-
...webpackOptions.plugins ?? [],
|
|
263
|
-
],
|
|
278
|
+
plugins: getWebpackPlugins(webpackOptions),
|
|
264
279
|
resolve: webpackResolve,
|
|
265
280
|
};
|
|
266
281
|
// Special case: I'm not sure I can move options in the task-specific part of
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cley_faye/boilerplate",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.21.0",
|
|
4
4
|
"description": "Boilerplate code generator for generic projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -22,14 +22,15 @@
|
|
|
22
22
|
"homepage": "https://github.com/CleyFaye/boilerplate#readme",
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@keeex/eslint-config": "^1.11.5",
|
|
25
|
-
"@types/express": "^4.17.
|
|
25
|
+
"@types/express": "^4.17.19",
|
|
26
26
|
"@types/grunt": "^0.4.28",
|
|
27
27
|
"@types/http-errors": "^2.0.2",
|
|
28
28
|
"@types/minimist": "^1.2.3",
|
|
29
|
-
"@types/node": "^18.18.
|
|
30
|
-
"@
|
|
31
|
-
"@typescript-eslint/
|
|
32
|
-
"eslint": "^
|
|
29
|
+
"@types/node": "^18.18.4",
|
|
30
|
+
"@types/webpack-bundle-analyzer": "^4.6.1",
|
|
31
|
+
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
|
32
|
+
"@typescript-eslint/parser": "^6.7.5",
|
|
33
|
+
"eslint": "^8.51.0",
|
|
33
34
|
"eslint-plugin-deprecation": "^2.0.0",
|
|
34
35
|
"eslint-plugin-import": "^2.28.1",
|
|
35
36
|
"eslint-plugin-promise": "^6.1.1",
|
|
@@ -43,7 +44,7 @@
|
|
|
43
44
|
"logform": "^2.5.1",
|
|
44
45
|
"typescript": "^5.2.2",
|
|
45
46
|
"webpack": "^5.88.2",
|
|
46
|
-
"winston": "^3.
|
|
47
|
+
"winston": "^3.11.0"
|
|
47
48
|
},
|
|
48
49
|
"peerDependencies": {
|
|
49
50
|
"@babel/core": "7.x",
|
|
@@ -61,10 +62,11 @@
|
|
|
61
62
|
"grunt-contrib-pug": "3.x",
|
|
62
63
|
"grunt-contrib-watch": "1.x",
|
|
63
64
|
"grunt-sass": "3.x",
|
|
64
|
-
"grunt-webpack": "5.x",
|
|
65
|
+
"grunt-webpack": "5.x||6.x",
|
|
65
66
|
"minimist": "^1.2.8",
|
|
66
67
|
"sass": "1.x",
|
|
67
68
|
"ts-loader": "^9.4.1",
|
|
69
|
+
"webpack-bundle-analyzer": "^4.9.1",
|
|
68
70
|
"winston": "3.x"
|
|
69
71
|
},
|
|
70
72
|
"peerDependenciesMeta": {
|