@cley_faye/boilerplate 3.21.3 → 4.0.2
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 +7 -219
- package/bin/serve_spa.js +0 -1
- package/lib/bin/serve_spa.js +67 -39
- package/lib/express/middlewares/singlepageapp.d.ts +2 -2
- package/lib/express/middlewares/singlepageapp.js +20 -13
- package/lib/grunt/args.d.ts +14 -42
- package/lib/grunt/args.js +27 -41
- package/lib/grunt/reactapp/copy.d.ts +8 -34
- package/lib/grunt/reactapp/copy.js +47 -49
- package/lib/grunt/reactapp/image.d.ts +8 -23
- package/lib/grunt/reactapp/image.js +45 -42
- package/lib/grunt/reactapp/pug.d.ts +8 -30
- package/lib/grunt/reactapp/pug.js +49 -50
- package/lib/grunt/reactapp/sass.d.ts +8 -29
- package/lib/grunt/reactapp/sass.js +48 -43
- package/lib/grunt/reactapp/util.d.ts +5 -9
- package/lib/grunt/reactapp/util.js +12 -15
- package/lib/grunt/reactapp/webpack.d.ts +9 -80
- package/lib/grunt/reactapp/webpack.js +71 -125
- package/lib/grunt/reactapp.d.ts +22 -64
- package/lib/grunt/reactapp.js +70 -93
- package/lib/grunt/util.d.ts +4 -7
- package/lib/grunt/util.js +5 -8
- package/lib/grunt.d.ts +2 -3
- package/lib/grunt.js +5 -5
- package/lib/util.js +5 -4
- package/package.json +23 -30
- package/grunt.js +0 -3
- package/lib/express/autoclose.d.ts +0 -17
- package/lib/express/autoclose.js +0 -76
- package/lib/express/logger.d.ts +0 -25
- package/lib/express/logger.js +0 -132
- package/lib/express/middlewares/bodylogger.d.ts +0 -9
- package/lib/express/middlewares/bodylogger.js +0 -90
- package/lib/express/pipelinebuilder.d.ts +0 -115
- package/lib/express/pipelinebuilder.js +0 -288
- package/lib/express/unprocessableentityerror.d.ts +0 -8
- package/lib/express/unprocessableentityerror.js +0 -57
- package/lib/express.d.ts +0 -156
- package/lib/express.js +0 -218
- package/lib/repl.d.ts +0 -27
- package/lib/repl.js +0 -68
- package/lib/winston.d.ts +0 -38
- package/lib/winston.js +0 -224
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import { type HandlerFunctionResult } from "../reactapp.js";
|
|
2
|
+
import { type BaseOptions } from "../util.js";
|
|
3
|
+
import * as util from "./util.js";
|
|
4
4
|
interface SassOptionsOptions {
|
|
5
5
|
implementation?: Record<string, unknown>;
|
|
6
6
|
}
|
|
@@ -12,35 +12,14 @@ export interface SassOptions extends BaseOptions {
|
|
|
12
12
|
}
|
|
13
13
|
/** Add an sass processing task to the Grunt configuration
|
|
14
14
|
*
|
|
15
|
-
* @param gruntConfig
|
|
16
|
-
* Grunt configuration to add the task to
|
|
15
|
+
* @param gruntConfig - Grunt configuration to add the task to
|
|
17
16
|
*
|
|
18
|
-
* @param targetName
|
|
19
|
-
* Name of the target for the image minification task.
|
|
17
|
+
* @param targetName - Name of the target for the image minification task.
|
|
20
18
|
*
|
|
21
|
-
* @param sassOptions
|
|
22
|
-
* Options for the sass task configuration.
|
|
19
|
+
* @param sassOptions - Options for the sass task configuration.
|
|
23
20
|
*
|
|
24
|
-
* @
|
|
25
|
-
* Options to pass to grunt-sass.
|
|
26
|
-
*
|
|
27
|
-
* @param [sassOptions.options.implementation]
|
|
28
|
-
* Implementation to use. Defaults to require("sass").
|
|
29
|
-
*
|
|
30
|
-
* @param [sassOptions.sourcePath]
|
|
31
|
-
* Path where the pug templates can be found. Subdirectories will be searched.
|
|
32
|
-
* Default to "webres/<targetName>"
|
|
33
|
-
*
|
|
34
|
-
* @param [sassOptions.outputPath]
|
|
35
|
-
* Path to put the output files into. The source directory tree will be
|
|
36
|
-
* preserved.
|
|
37
|
-
* Defaults to "dist/<targetName>"
|
|
38
|
-
*
|
|
39
|
-
* @param [sassOptions.fileSuffix]
|
|
40
|
-
* Output files suffix. Defaults to ".css"
|
|
41
|
-
*
|
|
42
|
-
* @return
|
|
21
|
+
* @returns
|
|
43
22
|
* List of tasks added to the grunt configuration
|
|
44
23
|
*/
|
|
45
|
-
export declare const handle: (gruntConfig: GruntConfig, targetName: string, sassOptions: SassOptions) => HandlerFunctionResult;
|
|
24
|
+
export declare const handle: (gruntConfig: util.GruntConfig, targetName: string, sassOptions: SassOptions) => HandlerFunctionResult;
|
|
46
25
|
export {};
|
|
@@ -25,80 +25,85 @@
|
|
|
25
25
|
*
|
|
26
26
|
*/
|
|
27
27
|
"use strict";
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}) : (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
o[k2] = m[k];
|
|
38
|
+
}));
|
|
39
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
+
}) : function(o, v) {
|
|
42
|
+
o["default"] = v;
|
|
43
|
+
});
|
|
44
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
45
|
+
var ownKeys = function(o) {
|
|
46
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
47
|
+
var ar = [];
|
|
48
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
49
|
+
return ar;
|
|
50
|
+
};
|
|
51
|
+
return ownKeys(o);
|
|
52
|
+
};
|
|
53
|
+
return function (mod) {
|
|
54
|
+
if (mod && mod.__esModule) return mod;
|
|
55
|
+
var result = {};
|
|
56
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
57
|
+
__setModuleDefault(result, mod);
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
})();
|
|
28
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
62
|
exports.handle = void 0;
|
|
30
63
|
const path_1 = require("path");
|
|
31
|
-
const
|
|
64
|
+
const util = __importStar(require("./util.js"));
|
|
32
65
|
/** File extensions handled by this task */
|
|
33
|
-
const handledExtensions = [
|
|
34
|
-
".scss",
|
|
35
|
-
".sass",
|
|
36
|
-
];
|
|
66
|
+
const handledExtensions = [".scss", ".sass"];
|
|
37
67
|
/** Add an sass processing task to the Grunt configuration
|
|
38
68
|
*
|
|
39
|
-
* @param gruntConfig
|
|
40
|
-
* Grunt configuration to add the task to
|
|
41
|
-
*
|
|
42
|
-
* @param targetName
|
|
43
|
-
* Name of the target for the image minification task.
|
|
44
|
-
*
|
|
45
|
-
* @param sassOptions
|
|
46
|
-
* Options for the sass task configuration.
|
|
47
|
-
*
|
|
48
|
-
* @param sassOptions.options
|
|
49
|
-
* Options to pass to grunt-sass.
|
|
50
|
-
*
|
|
51
|
-
* @param [sassOptions.options.implementation]
|
|
52
|
-
* Implementation to use. Defaults to require("sass").
|
|
69
|
+
* @param gruntConfig - Grunt configuration to add the task to
|
|
53
70
|
*
|
|
54
|
-
* @param
|
|
55
|
-
* Path where the pug templates can be found. Subdirectories will be searched.
|
|
56
|
-
* Default to "webres/<targetName>"
|
|
71
|
+
* @param targetName - Name of the target for the image minification task.
|
|
57
72
|
*
|
|
58
|
-
* @param
|
|
59
|
-
* Path to put the output files into. The source directory tree will be
|
|
60
|
-
* preserved.
|
|
61
|
-
* Defaults to "dist/<targetName>"
|
|
73
|
+
* @param sassOptions - Options for the sass task configuration.
|
|
62
74
|
*
|
|
63
|
-
* @
|
|
64
|
-
* Output files suffix. Defaults to ".css"
|
|
65
|
-
*
|
|
66
|
-
* @return
|
|
75
|
+
* @returns
|
|
67
76
|
* List of tasks added to the grunt configuration
|
|
68
77
|
*/
|
|
69
78
|
const handle = (gruntConfig, targetName, sassOptions) => {
|
|
70
79
|
const handledFiles = [
|
|
71
|
-
...handledExtensions.map(ext => `**/*${ext}`),
|
|
72
|
-
...handledExtensions.map(ext => `!**/_*${ext}`),
|
|
73
|
-
...handledExtensions.map(ext => `!**/*.inc${ext}`),
|
|
80
|
+
...handledExtensions.map((ext) => `**/*${ext}`),
|
|
81
|
+
...handledExtensions.map((ext) => `!**/_*${ext}`),
|
|
82
|
+
...handledExtensions.map((ext) => `!**/*.inc${ext}`),
|
|
74
83
|
];
|
|
75
84
|
const sassTask = {
|
|
76
85
|
options: { ...sassOptions.options },
|
|
77
86
|
files: [
|
|
78
87
|
{
|
|
79
|
-
expand: true,
|
|
80
88
|
cwd: sassOptions.sourcePath ?? (0, path_1.join)("webres", targetName),
|
|
81
|
-
src: handledFiles,
|
|
82
89
|
dest: sassOptions.outputPath ?? (0, path_1.join)("dist", targetName),
|
|
90
|
+
expand: true,
|
|
83
91
|
ext: sassOptions.fileSuffix ?? ".css",
|
|
92
|
+
src: handledFiles,
|
|
84
93
|
},
|
|
85
94
|
],
|
|
86
95
|
};
|
|
87
96
|
if (sassTask.options.implementation === undefined) {
|
|
88
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
89
98
|
sassTask.options.implementation = require("sass");
|
|
90
99
|
}
|
|
91
|
-
const requiredTasks = [
|
|
100
|
+
const requiredTasks = [util.insertTask(gruntConfig, "sass", targetName, sassTask)];
|
|
92
101
|
const watchTasks = [
|
|
93
102
|
{
|
|
94
|
-
filesToWatch: [...handledExtensions.map(ext => `**/*${ext}`)],
|
|
103
|
+
filesToWatch: [...handledExtensions.map((ext) => `**/*${ext}`)],
|
|
95
104
|
taskToRun: requiredTasks[0],
|
|
96
105
|
},
|
|
97
106
|
];
|
|
98
|
-
return {
|
|
99
|
-
requiredTasks,
|
|
100
|
-
handledFiles,
|
|
101
|
-
watchTasks,
|
|
102
|
-
};
|
|
107
|
+
return { handledFiles, requiredTasks, watchTasks };
|
|
103
108
|
};
|
|
104
109
|
exports.handle = handle;
|
|
@@ -2,19 +2,15 @@ export type DynamicTaskFunc = () => Promise<void>;
|
|
|
2
2
|
export type GruntConfig = Record<string, Record<string, Record<string, unknown> | (() => void) | undefined>>;
|
|
3
3
|
/** Insert a new task in a grunt config object.
|
|
4
4
|
*
|
|
5
|
-
* @param gruntConfig
|
|
6
|
-
* The grunt configuration, before sending it to initConfig()
|
|
5
|
+
* @param gruntConfig - The grunt configuration, before sending it to initConfig()
|
|
7
6
|
*
|
|
8
|
-
* @param taskType
|
|
9
|
-
* The task type name (first level of grunt config object)
|
|
7
|
+
* @param taskType - The task type name (first level of grunt config object)
|
|
10
8
|
*
|
|
11
|
-
* @param taskName
|
|
12
|
-
* The task name under a givne type (second level of grunt config object)
|
|
9
|
+
* @param taskName - The task name under a givne type (second level of grunt config object)
|
|
13
10
|
*
|
|
14
|
-
* @param taskDef
|
|
15
|
-
* The task definition to insert
|
|
11
|
+
* @param taskDef - The task definition to insert
|
|
16
12
|
*
|
|
17
|
-
* @
|
|
13
|
+
* @returns
|
|
18
14
|
* The task full name to reference in registerTask()
|
|
19
15
|
*/
|
|
20
16
|
export declare const insertTask: (gruntConfig: GruntConfig, taskType: string, taskName: string, taskDef: Record<string, unknown>) => string;
|
|
@@ -29,25 +29,20 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.insertDynamicTask = exports.dynamicKey = exports.insertTask = void 0;
|
|
30
30
|
/** Insert a new task in a grunt config object.
|
|
31
31
|
*
|
|
32
|
-
* @param gruntConfig
|
|
33
|
-
* The grunt configuration, before sending it to initConfig()
|
|
32
|
+
* @param gruntConfig - The grunt configuration, before sending it to initConfig()
|
|
34
33
|
*
|
|
35
|
-
* @param taskType
|
|
36
|
-
* The task type name (first level of grunt config object)
|
|
34
|
+
* @param taskType - The task type name (first level of grunt config object)
|
|
37
35
|
*
|
|
38
|
-
* @param taskName
|
|
39
|
-
* The task name under a givne type (second level of grunt config object)
|
|
36
|
+
* @param taskName - The task name under a givne type (second level of grunt config object)
|
|
40
37
|
*
|
|
41
|
-
* @param taskDef
|
|
42
|
-
* The task definition to insert
|
|
38
|
+
* @param taskDef - The task definition to insert
|
|
43
39
|
*
|
|
44
|
-
* @
|
|
40
|
+
* @returns
|
|
45
41
|
* The task full name to reference in registerTask()
|
|
46
42
|
*/
|
|
47
43
|
const insertTask = (gruntConfig, taskType, taskName, taskDef) => {
|
|
48
|
-
if (!(taskType in gruntConfig))
|
|
44
|
+
if (!(taskType in gruntConfig))
|
|
49
45
|
gruntConfig[taskType] = {};
|
|
50
|
-
}
|
|
51
46
|
const taskFullName = `${taskType}:${taskName}`;
|
|
52
47
|
if (gruntConfig[taskType][taskName] !== undefined) {
|
|
53
48
|
throw new Error(`Grunt task ${taskFullName} already defined`);
|
|
@@ -58,14 +53,16 @@ const insertTask = (gruntConfig, taskType, taskName, taskDef) => {
|
|
|
58
53
|
exports.insertTask = insertTask;
|
|
59
54
|
exports.dynamicKey = "_dynamic";
|
|
60
55
|
const insertDynamicTask = (gruntConfig, taskType, taskName, task) => {
|
|
61
|
-
if (!(exports.dynamicKey in gruntConfig))
|
|
56
|
+
if (!(exports.dynamicKey in gruntConfig))
|
|
62
57
|
gruntConfig[exports.dynamicKey] = {};
|
|
63
|
-
}
|
|
64
58
|
const taskFullName = `${taskType}_${taskName}`;
|
|
65
59
|
gruntConfig[exports.dynamicKey][taskFullName] = function dynamicTask() {
|
|
66
60
|
const done = this.async();
|
|
67
|
-
task()
|
|
68
|
-
|
|
61
|
+
task()
|
|
62
|
+
// eslint-disable-next-line promise/prefer-await-to-then, promise/no-callback-in-promise
|
|
63
|
+
.then(() => done())
|
|
64
|
+
// eslint-disable-next-line promise/prefer-await-to-then, promise/no-callback-in-promise
|
|
65
|
+
.catch((e) => done(e));
|
|
69
66
|
};
|
|
70
67
|
return taskFullName;
|
|
71
68
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { ResolveOptions } from "webpack";
|
|
2
|
-
import { BaseOptions } from "../util.js";
|
|
3
|
-
import
|
|
4
|
-
import
|
|
1
|
+
import { type ResolveOptions } from "webpack";
|
|
2
|
+
import { type BaseOptions } from "../util.js";
|
|
3
|
+
import * as util from "./util.js";
|
|
4
|
+
import type * as reactApp from "../reactapp.js";
|
|
5
5
|
export interface WebpackLoadersOptions {
|
|
6
6
|
development?: boolean;
|
|
7
7
|
defines?: Record<string, string>;
|
|
@@ -15,27 +15,6 @@ export interface WebpackLoadersOptions {
|
|
|
15
15
|
/** Build the default webpack loaders list.
|
|
16
16
|
*
|
|
17
17
|
* Uses babel. Some options can be customized here.
|
|
18
|
-
*
|
|
19
|
-
* @param [options]
|
|
20
|
-
* @param [options.development]
|
|
21
|
-
* true for development-friendly options, false for production options
|
|
22
|
-
*
|
|
23
|
-
* @param [options.defines]
|
|
24
|
-
* List of defines to set using Babel transform-define
|
|
25
|
-
*
|
|
26
|
-
* @param [options.babel]
|
|
27
|
-
* @param [options.babel.corejs]
|
|
28
|
-
* Version of core-js to use (default to 3)
|
|
29
|
-
*
|
|
30
|
-
* @param [options.babel.targets]
|
|
31
|
-
* Browser targets (default to "> 2% and not dead, last 2 safari version, last 2 firefox version,
|
|
32
|
-
* last 2 chrome version, last 2 edge version, Firefox ESR")
|
|
33
|
-
*
|
|
34
|
-
* @param [options.babel.plugins]
|
|
35
|
-
* Plugins to add to babel
|
|
36
|
-
*
|
|
37
|
-
* @param [options.typescript]
|
|
38
|
-
* Add support for importing .ts and .tsx files
|
|
39
18
|
*/
|
|
40
19
|
export declare const webpackLoadersDefault: (options: WebpackLoadersOptions) => Array<Record<string, unknown>>;
|
|
41
20
|
export interface WebpackOptions extends BaseOptions {
|
|
@@ -57,64 +36,14 @@ export interface WebpackOptions extends BaseOptions {
|
|
|
57
36
|
}
|
|
58
37
|
/** Add a webpack task for the reactApp recipe
|
|
59
38
|
*
|
|
60
|
-
* @param gruntConfig
|
|
61
|
-
* Grunt configuration to add the task to
|
|
62
|
-
*
|
|
63
|
-
* @param targetName
|
|
64
|
-
* Name of the target for the image minification task.
|
|
65
|
-
*
|
|
66
|
-
* @param webpackOptions
|
|
67
|
-
* Options for the webpack task configuration.
|
|
68
|
-
*
|
|
69
|
-
* @param [webpackOptions.options]
|
|
70
|
-
* Options for webpack
|
|
71
|
-
*
|
|
72
|
-
* @param [webpackOptions.entry]
|
|
73
|
-
* List of entrypoints.
|
|
74
|
-
* Defaults to {targetName: "webres/<targetName>/js/loader.js"}
|
|
75
|
-
*
|
|
76
|
-
* @param [webpackOptions.externals]
|
|
77
|
-
* List of external libraries.
|
|
78
|
-
* Defaults to {}.
|
|
79
|
-
*
|
|
80
|
-
* @param [webpackOptions.output]
|
|
81
|
-
* Configure webpack output location and name.
|
|
82
|
-
* Defaults to {path: "dist/<targetName>/js", filename: "[name].js"}
|
|
83
|
-
*
|
|
84
|
-
* @param [webpackOptions.output.path]
|
|
85
|
-
* Path to put the compiled files into.
|
|
86
|
-
* It is possible to pass a completely different object as webpackOptions.output
|
|
87
|
-
* than expected, it will be handed to webpack as-is.
|
|
88
|
-
*
|
|
89
|
-
* @param [webpackOptions.output.filename]
|
|
90
|
-
* Template for output filename.
|
|
91
|
-
* It is possible to pass a completely different object as webpackOptions.output
|
|
92
|
-
* than expected, it will be handed to webpack as-is.
|
|
93
|
-
*
|
|
94
|
-
* @param [webpackOptions.loaders]
|
|
95
|
-
* Configuration for webpack loaders. See webpack doc about module.rules.
|
|
96
|
-
* Defaults to using babel with React configuration.
|
|
97
|
-
* To customize the default behavior build an object with
|
|
98
|
-
* webpackLoadersDefault().
|
|
99
|
-
*
|
|
100
|
-
* @param [webpackOptions.plugins]
|
|
101
|
-
* Configuration for webpack plugins. See webpack doc about plugins.
|
|
102
|
-
*
|
|
103
|
-
* @param [webpackOptions.babelPlugins]
|
|
104
|
-
* List of extra babel plugins.
|
|
105
|
-
*
|
|
106
|
-
* @param [webpackOptions.mode]
|
|
107
|
-
* Build mode. "development", "production" or "none".
|
|
108
|
-
* Defaults to "development"
|
|
39
|
+
* @param gruntConfig - Grunt configuration to add the task to
|
|
109
40
|
*
|
|
110
|
-
* @param
|
|
111
|
-
* Generate a bundle report HTML file.
|
|
41
|
+
* @param targetName - Name of the target for the image minification task.
|
|
112
42
|
*
|
|
113
|
-
* @param
|
|
114
|
-
* Allow loading typescript source for webpack/babel.
|
|
43
|
+
* @param webpackOptions - Options for the webpack task configuration.
|
|
115
44
|
*
|
|
116
|
-
* @
|
|
45
|
+
* @returns
|
|
117
46
|
* List of tasks added.
|
|
118
47
|
* This function add "webpack:<targetName>".
|
|
119
48
|
*/
|
|
120
|
-
export declare const handle: (gruntConfig: GruntConfig, targetName: string, webpackOptions: WebpackOptions) => HandlerFunctionResult;
|
|
49
|
+
export declare const handle: (gruntConfig: util.GruntConfig, targetName: string, webpackOptions: WebpackOptions) => reactApp.HandlerFunctionResult;
|
|
@@ -25,30 +25,62 @@
|
|
|
25
25
|
*
|
|
26
26
|
*/
|
|
27
27
|
"use strict";
|
|
28
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
29
|
+
if (k2 === undefined) k2 = k;
|
|
30
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
31
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
32
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(o, k2, desc);
|
|
35
|
+
}) : (function(o, m, k, k2) {
|
|
36
|
+
if (k2 === undefined) k2 = k;
|
|
37
|
+
o[k2] = m[k];
|
|
38
|
+
}));
|
|
39
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
40
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
41
|
+
}) : function(o, v) {
|
|
42
|
+
o["default"] = v;
|
|
43
|
+
});
|
|
44
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
45
|
+
var ownKeys = function(o) {
|
|
46
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
47
|
+
var ar = [];
|
|
48
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
49
|
+
return ar;
|
|
50
|
+
};
|
|
51
|
+
return ownKeys(o);
|
|
52
|
+
};
|
|
53
|
+
return function (mod) {
|
|
54
|
+
if (mod && mod.__esModule) return mod;
|
|
55
|
+
var result = {};
|
|
56
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
57
|
+
__setModuleDefault(result, mod);
|
|
58
|
+
return result;
|
|
59
|
+
};
|
|
60
|
+
})();
|
|
28
61
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
62
|
exports.handle = exports.webpackLoadersDefault = void 0;
|
|
30
|
-
const path_1 = require("path");
|
|
31
63
|
const node_fs_1 = require("node:fs");
|
|
64
|
+
const path_1 = require("path");
|
|
32
65
|
const webpack_bundle_analyzer_1 = require("webpack-bundle-analyzer");
|
|
33
|
-
const
|
|
66
|
+
const util = __importStar(require("./util.js"));
|
|
34
67
|
const defaultCoreJS = 3;
|
|
35
68
|
const defaultLoadersDefine = (options) => [
|
|
36
69
|
"transform-define",
|
|
37
70
|
{
|
|
38
71
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
39
|
-
"process.env.BUILD_TYPE": options.development
|
|
40
|
-
? "development"
|
|
41
|
-
: "production",
|
|
72
|
+
"process.env.BUILD_TYPE": options.development ? "development" : "production",
|
|
42
73
|
...options.defines,
|
|
43
74
|
},
|
|
44
75
|
];
|
|
45
76
|
const defaultLoadersPresetEnv = (options) => [
|
|
46
77
|
"@babel/preset-env",
|
|
47
78
|
{
|
|
48
|
-
|
|
49
|
-
useBuiltIns: "usage",
|
|
50
|
-
corejs: (options.babel?.corejs) ?? defaultCoreJS,
|
|
79
|
+
corejs: options.babel?.corejs ?? defaultCoreJS,
|
|
51
80
|
modules: false,
|
|
81
|
+
targets: options.babel?.targets ??
|
|
82
|
+
"> 2% and not dead, last 2 safari version, last 2 firefox version, last 2 chrome version, last 2 edge version, Firefox ESR",
|
|
83
|
+
useBuiltIns: "usage",
|
|
52
84
|
},
|
|
53
85
|
];
|
|
54
86
|
const defaultLoadersReact = (options) => [
|
|
@@ -58,48 +90,19 @@ const defaultLoadersReact = (options) => [
|
|
|
58
90
|
/** Build the default webpack loaders list.
|
|
59
91
|
*
|
|
60
92
|
* Uses babel. Some options can be customized here.
|
|
61
|
-
*
|
|
62
|
-
* @param [options]
|
|
63
|
-
* @param [options.development]
|
|
64
|
-
* true for development-friendly options, false for production options
|
|
65
|
-
*
|
|
66
|
-
* @param [options.defines]
|
|
67
|
-
* List of defines to set using Babel transform-define
|
|
68
|
-
*
|
|
69
|
-
* @param [options.babel]
|
|
70
|
-
* @param [options.babel.corejs]
|
|
71
|
-
* Version of core-js to use (default to 3)
|
|
72
|
-
*
|
|
73
|
-
* @param [options.babel.targets]
|
|
74
|
-
* Browser targets (default to "> 2% and not dead, last 2 safari version, last 2 firefox version,
|
|
75
|
-
* last 2 chrome version, last 2 edge version, Firefox ESR")
|
|
76
|
-
*
|
|
77
|
-
* @param [options.babel.plugins]
|
|
78
|
-
* Plugins to add to babel
|
|
79
|
-
*
|
|
80
|
-
* @param [options.typescript]
|
|
81
|
-
* Add support for importing .ts and .tsx files
|
|
82
93
|
*/
|
|
83
94
|
const webpackLoadersDefault = (options) => {
|
|
84
|
-
const allFilesCheck = options.typescript
|
|
85
|
-
? /.(?:js|ts|tsx)$/u
|
|
86
|
-
: /.js$/u;
|
|
95
|
+
const allFilesCheck = options.typescript ? /.(?:js|ts|tsx)$/u : /.js$/u;
|
|
87
96
|
const res = [
|
|
88
97
|
{
|
|
89
|
-
test: allFilesCheck,
|
|
90
98
|
exclude: /node_modules/u,
|
|
99
|
+
test: allFilesCheck,
|
|
91
100
|
use: {
|
|
92
101
|
loader: "babel-loader",
|
|
93
102
|
options: {
|
|
94
103
|
cacheDirectory: true,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
defaultLoadersReact(options),
|
|
98
|
-
],
|
|
99
|
-
plugins: [
|
|
100
|
-
defaultLoadersDefine(options),
|
|
101
|
-
...(options.babel?.plugins ?? []),
|
|
102
|
-
],
|
|
104
|
+
plugins: [defaultLoadersDefine(options), ...(options.babel?.plugins ?? [])],
|
|
105
|
+
presets: [defaultLoadersPresetEnv(options), defaultLoadersReact(options)],
|
|
103
106
|
},
|
|
104
107
|
},
|
|
105
108
|
},
|
|
@@ -107,24 +110,26 @@ const webpackLoadersDefault = (options) => {
|
|
|
107
110
|
if (options.typescript) {
|
|
108
111
|
const alternativeConfig = "tsconfig-tsloader.json";
|
|
109
112
|
const tsLoader = (0, node_fs_1.existsSync)(alternativeConfig)
|
|
110
|
-
? [
|
|
113
|
+
? [
|
|
114
|
+
{
|
|
111
115
|
loader: "ts-loader",
|
|
112
116
|
options: { configFile: alternativeConfig },
|
|
113
|
-
}
|
|
117
|
+
},
|
|
118
|
+
]
|
|
114
119
|
: "ts-loader";
|
|
115
120
|
res.push({
|
|
121
|
+
exclude: /node_modules/u,
|
|
116
122
|
test: /.(?:ts|tsx)$/u,
|
|
117
123
|
use: tsLoader,
|
|
118
|
-
exclude: /node_modules/u,
|
|
119
124
|
});
|
|
120
125
|
}
|
|
121
126
|
return res;
|
|
122
127
|
};
|
|
123
128
|
exports.webpackLoadersDefault = webpackLoadersDefault;
|
|
124
129
|
const computeWebpackOutput = (webpackOptions, targetName) => webpackOptions.output ?? {
|
|
125
|
-
path: (0, path_1.resolve)("dist", targetName, "js"),
|
|
126
|
-
filename: "[name].js",
|
|
127
130
|
chunkFilename: "[name]-[fullhash].js",
|
|
131
|
+
filename: "[name].js",
|
|
132
|
+
path: (0, path_1.resolve)("dist", targetName, "js"),
|
|
128
133
|
};
|
|
129
134
|
const lastNamePosition = 2;
|
|
130
135
|
const getHandledFiles = (webpackEntry) => Object.keys(webpackEntry).reduce((acc, cur) => {
|
|
@@ -155,134 +160,75 @@ const getWatchTasks = (webpackOptions, targetName) => {
|
|
|
155
160
|
return [];
|
|
156
161
|
};
|
|
157
162
|
const registerTasks = (gruntConfig, targetName, webpackConfig) => {
|
|
158
|
-
|
|
163
|
+
util.insertTask(gruntConfig, "webpack", `${targetName}_watch`, {
|
|
159
164
|
...webpackConfig,
|
|
160
165
|
watch: true,
|
|
161
166
|
});
|
|
162
|
-
return [
|
|
163
|
-
(0, util_js_1.insertTask)(gruntConfig, "webpack", targetName, webpackConfig),
|
|
164
|
-
];
|
|
167
|
+
return [util.insertTask(gruntConfig, "webpack", targetName, webpackConfig)];
|
|
165
168
|
};
|
|
166
169
|
const computeWebpackResolve = (webpackOptions) => {
|
|
167
170
|
const res = { ...webpackOptions.resolve };
|
|
168
171
|
if (webpackOptions.typescript) {
|
|
169
|
-
|
|
170
|
-
res.extensionAlias = {};
|
|
171
|
-
}
|
|
172
|
+
res.extensionAlias ?? (res.extensionAlias = {});
|
|
172
173
|
res.extensionAlias[".js"] = [".ts", ".tsx", ".js", ".jsx"];
|
|
173
174
|
res.extensionAlias[".mjs"] = [".mts", ".mtsx", ".mjs", ".mjsx"];
|
|
174
175
|
}
|
|
175
176
|
return res;
|
|
176
177
|
};
|
|
177
178
|
const getWebpackPlugins = (webpackOptions) => {
|
|
178
|
-
const plugins = [
|
|
179
|
-
...webpackOptions.plugins ?? [],
|
|
180
|
-
];
|
|
179
|
+
const plugins = [...(webpackOptions.plugins ?? [])];
|
|
181
180
|
if (webpackOptions.generateReport) {
|
|
182
181
|
plugins.push(new webpack_bundle_analyzer_1.BundleAnalyzerPlugin({
|
|
183
182
|
analyzerMode: "static",
|
|
184
|
-
reportFilename: (0, path_1.join)(process.cwd(), "bundle_report.html"),
|
|
185
183
|
openAnalyzer: false,
|
|
184
|
+
reportFilename: (0, path_1.join)(process.cwd(), "bundle_report.html"),
|
|
186
185
|
}));
|
|
187
186
|
}
|
|
188
187
|
return plugins;
|
|
189
188
|
};
|
|
190
189
|
/** Add a webpack task for the reactApp recipe
|
|
191
190
|
*
|
|
192
|
-
* @param gruntConfig
|
|
193
|
-
* Grunt configuration to add the task to
|
|
194
|
-
*
|
|
195
|
-
* @param targetName
|
|
196
|
-
* Name of the target for the image minification task.
|
|
197
|
-
*
|
|
198
|
-
* @param webpackOptions
|
|
199
|
-
* Options for the webpack task configuration.
|
|
200
|
-
*
|
|
201
|
-
* @param [webpackOptions.options]
|
|
202
|
-
* Options for webpack
|
|
203
|
-
*
|
|
204
|
-
* @param [webpackOptions.entry]
|
|
205
|
-
* List of entrypoints.
|
|
206
|
-
* Defaults to {targetName: "webres/<targetName>/js/loader.js"}
|
|
207
|
-
*
|
|
208
|
-
* @param [webpackOptions.externals]
|
|
209
|
-
* List of external libraries.
|
|
210
|
-
* Defaults to {}.
|
|
211
|
-
*
|
|
212
|
-
* @param [webpackOptions.output]
|
|
213
|
-
* Configure webpack output location and name.
|
|
214
|
-
* Defaults to {path: "dist/<targetName>/js", filename: "[name].js"}
|
|
215
|
-
*
|
|
216
|
-
* @param [webpackOptions.output.path]
|
|
217
|
-
* Path to put the compiled files into.
|
|
218
|
-
* It is possible to pass a completely different object as webpackOptions.output
|
|
219
|
-
* than expected, it will be handed to webpack as-is.
|
|
220
|
-
*
|
|
221
|
-
* @param [webpackOptions.output.filename]
|
|
222
|
-
* Template for output filename.
|
|
223
|
-
* It is possible to pass a completely different object as webpackOptions.output
|
|
224
|
-
* than expected, it will be handed to webpack as-is.
|
|
225
|
-
*
|
|
226
|
-
* @param [webpackOptions.loaders]
|
|
227
|
-
* Configuration for webpack loaders. See webpack doc about module.rules.
|
|
228
|
-
* Defaults to using babel with React configuration.
|
|
229
|
-
* To customize the default behavior build an object with
|
|
230
|
-
* webpackLoadersDefault().
|
|
231
|
-
*
|
|
232
|
-
* @param [webpackOptions.plugins]
|
|
233
|
-
* Configuration for webpack plugins. See webpack doc about plugins.
|
|
191
|
+
* @param gruntConfig - Grunt configuration to add the task to
|
|
234
192
|
*
|
|
235
|
-
* @param
|
|
236
|
-
* List of extra babel plugins.
|
|
193
|
+
* @param targetName - Name of the target for the image minification task.
|
|
237
194
|
*
|
|
238
|
-
* @param
|
|
239
|
-
* Build mode. "development", "production" or "none".
|
|
240
|
-
* Defaults to "development"
|
|
195
|
+
* @param webpackOptions - Options for the webpack task configuration.
|
|
241
196
|
*
|
|
242
|
-
* @
|
|
243
|
-
* Generate a bundle report HTML file.
|
|
244
|
-
*
|
|
245
|
-
* @param [webpackOptions.typescript]
|
|
246
|
-
* Allow loading typescript source for webpack/babel.
|
|
247
|
-
*
|
|
248
|
-
* @return
|
|
197
|
+
* @returns
|
|
249
198
|
* List of tasks added.
|
|
250
199
|
* This function add "webpack:<targetName>".
|
|
251
200
|
*/
|
|
252
201
|
const handle = (gruntConfig, targetName, webpackOptions) => {
|
|
253
|
-
const webpackEntry = webpackOptions.entry
|
|
254
|
-
|
|
202
|
+
const webpackEntry = webpackOptions.entry ?? {
|
|
203
|
+
[targetName]: (0, path_1.join)("webres", targetName, "js", "loader.js"),
|
|
204
|
+
};
|
|
255
205
|
const handledFiles = getHandledFiles(webpackEntry);
|
|
256
206
|
const webpackOutput = computeWebpackOutput(webpackOptions, targetName);
|
|
257
|
-
const webpackLoaders = webpackOptions.loaders
|
|
258
|
-
|
|
259
|
-
development: webpackOptions.mode === "development",
|
|
260
|
-
defines: webpackOptions.defines,
|
|
207
|
+
const webpackLoaders = webpackOptions.loaders ??
|
|
208
|
+
(0, exports.webpackLoadersDefault)({
|
|
261
209
|
babel: { plugins: webpackOptions.babelPlugins },
|
|
210
|
+
defines: webpackOptions.defines,
|
|
211
|
+
development: webpackOptions.mode === "development",
|
|
262
212
|
typescript: webpackOptions.typescript,
|
|
263
213
|
});
|
|
264
214
|
const webpackResolve = computeWebpackResolve(webpackOptions);
|
|
265
215
|
const webpackConfig = {
|
|
266
|
-
mode: webpackOptions.mode,
|
|
267
216
|
devtool: webpackOptions.mode === "development" ? "eval-source-map" : false,
|
|
268
217
|
entry: webpackEntry,
|
|
269
|
-
output: webpackOutput,
|
|
270
218
|
externals: webpackOptions.externals,
|
|
219
|
+
mode: webpackOptions.mode,
|
|
271
220
|
module: { rules: webpackLoaders },
|
|
221
|
+
output: webpackOutput,
|
|
272
222
|
plugins: getWebpackPlugins(webpackOptions),
|
|
273
223
|
resolve: webpackResolve,
|
|
274
224
|
};
|
|
275
225
|
// Special case: I'm not sure I can move options in the task-specific part of
|
|
276
226
|
// the configuration, so I add it at the toplevel of the "webpack" task.
|
|
277
227
|
if (webpackOptions.options) {
|
|
278
|
-
|
|
228
|
+
util.insertTask(gruntConfig, "webpack", "options", webpackOptions.options);
|
|
279
229
|
}
|
|
280
230
|
const requiredTasks = registerTasks(gruntConfig, targetName, webpackConfig);
|
|
281
231
|
const watchTasks = getWatchTasks(webpackOptions, targetName);
|
|
282
|
-
return {
|
|
283
|
-
requiredTasks,
|
|
284
|
-
handledFiles,
|
|
285
|
-
watchTasks,
|
|
286
|
-
};
|
|
232
|
+
return { handledFiles, requiredTasks, watchTasks, };
|
|
287
233
|
};
|
|
288
234
|
exports.handle = handle;
|