@pinnacle0/webpack-util 0.3.16-beta1 → 0.3.16-beta2
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/package.json +1 -1
- package/src/CanadyarnRunner.d.ts +14 -0
- package/src/CanadyarnRunner.js +38 -0
- package/src/CanadyarnRunner.js.map +1 -0
- package/src/CodeStyleChecker.d.ts +10 -0
- package/src/CodeStyleChecker.js +44 -0
- package/src/CodeStyleChecker.js.map +1 -0
- package/src/Constant.d.ts +21 -0
- package/src/{Constant.ts → Constant.js} +5 -1
- package/src/Constant.js.map +1 -0
- package/src/CoreUtil.d.ts +11 -0
- package/src/CoreUtil.js +26 -0
- package/src/CoreUtil.js.map +1 -0
- package/src/ProjectStructureChecker.d.ts +18 -0
- package/src/ProjectStructureChecker.js +113 -0
- package/src/ProjectStructureChecker.js.map +1 -0
- package/src/TestRunner.d.ts +8 -0
- package/src/TestRunner.js +30 -0
- package/src/TestRunner.js.map +1 -0
- package/src/WebpackBuilder.d.ts +38 -0
- package/src/{WebpackBuilder.ts → WebpackBuilder.js} +49 -69
- package/src/WebpackBuilder.js.map +1 -0
- package/src/WebpackConfigGenerator/ConfigEntryDescriptorsFactory.d.ts +13 -0
- package/src/WebpackConfigGenerator/{ConfigEntryDescriptorsFactory.ts → ConfigEntryDescriptorsFactory.js} +29 -36
- package/src/WebpackConfigGenerator/ConfigEntryDescriptorsFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.d.ts +9 -0
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.js +20 -0
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/css.plugin.d.ts +16 -0
- package/src/WebpackConfigGenerator/Plugin/css.plugin.js +33 -0
- package/src/WebpackConfigGenerator/Plugin/css.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/esbuild.plugin.d.ts +2 -0
- package/src/WebpackConfigGenerator/Plugin/esbuild.plugin.js +14 -0
- package/src/WebpackConfigGenerator/Plugin/esbuild.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/html.plugin.d.ts +16 -0
- package/src/WebpackConfigGenerator/Plugin/html.plugin.js +48 -0
- package/src/WebpackConfigGenerator/Plugin/html.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/index.d.ts +29 -0
- package/src/WebpackConfigGenerator/Plugin/index.js +34 -0
- package/src/WebpackConfigGenerator/Plugin/index.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/moment.plugin.d.ts +10 -0
- package/src/WebpackConfigGenerator/Plugin/{moment.plugin.ts → moment.plugin.js} +12 -5
- package/src/WebpackConfigGenerator/Plugin/moment.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.d.ts +4 -0
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.js +28 -0
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.d.ts +16 -0
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.js +31 -0
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.d.ts +14 -0
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.js +24 -0
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/RegExpUtil.d.ts +4 -0
- package/src/WebpackConfigGenerator/Rule/{RegExpUtil.ts → RegExpUtil.js} +14 -8
- package/src/WebpackConfigGenerator/Rule/RegExpUtil.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin.d.ts +13 -0
- package/src/WebpackConfigGenerator/Rule/{core-fe-hmr-babel-plugin.ts → core-fe-hmr-babel-plugin.js} +9 -43
- package/src/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/image.rule.d.ts +9 -0
- package/src/WebpackConfigGenerator/Rule/{image.rule.ts → image.rule.js} +8 -5
- package/src/WebpackConfigGenerator/Rule/image.rule.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/index.d.ts +13 -0
- package/src/WebpackConfigGenerator/Rule/index.js +18 -0
- package/src/WebpackConfigGenerator/Rule/index.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/other.rule.d.ts +12 -0
- package/src/WebpackConfigGenerator/Rule/other.rule.js +22 -0
- package/src/WebpackConfigGenerator/Rule/other.rule.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/stylesheet.rule.d.ts +17 -0
- package/src/WebpackConfigGenerator/Rule/{stylesheet.rule.ts → stylesheet.rule.js} +30 -34
- package/src/WebpackConfigGenerator/Rule/stylesheet.rule.js.map +1 -0
- package/src/WebpackConfigGenerator/Rule/ts.rule.d.ts +19 -0
- package/src/WebpackConfigGenerator/Rule/{ts.rule.ts → ts.rule.js} +16 -19
- package/src/WebpackConfigGenerator/Rule/ts.rule.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackConfigSerializationUtil.d.ts +10 -0
- package/src/WebpackConfigGenerator/{WebpackConfigSerializationUtil.ts → WebpackConfigSerializationUtil.js} +22 -23
- package/src/WebpackConfigGenerator/WebpackConfigSerializationUtil.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackEntryFactory.d.ts +9 -0
- package/src/WebpackConfigGenerator/WebpackEntryFactory.js +14 -0
- package/src/WebpackConfigGenerator/WebpackEntryFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.d.ts +11 -0
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.js +16 -0
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackResolveAliasFactory.d.ts +11 -0
- package/src/WebpackConfigGenerator/{WebpackResolveAliasFactory.ts → WebpackResolveAliasFactory.js} +13 -16
- package/src/WebpackConfigGenerator/WebpackResolveAliasFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.d.ts +7 -0
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.js +16 -0
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/WebpackResolveModulesFactory.d.ts +7 -0
- package/src/WebpackConfigGenerator/{WebpackResolveModulesFactory.ts → WebpackResolveModulesFactory.js} +7 -9
- package/src/WebpackConfigGenerator/WebpackResolveModulesFactory.js.map +1 -0
- package/src/WebpackConfigGenerator/index.d.ts +31 -0
- package/src/WebpackConfigGenerator/index.js +191 -0
- package/src/WebpackConfigGenerator/index.js.map +1 -0
- package/src/WebpackServerStarter.d.ts +28 -0
- package/src/WebpackServerStarter.js +111 -0
- package/src/WebpackServerStarter.js.map +1 -0
- package/src/index.d.ts +10 -0
- package/src/index.js +8 -0
- package/src/index.js.map +1 -0
- package/src/{type.ts → type.d.ts} +4 -8
- package/src/type.js +3 -0
- package/src/type.js.map +1 -0
- package/config/jest.config.ts +0 -35
- package/config/tsconfig.script.json +0 -11
- package/config/tsconfig.src.json +0 -12
- package/config/tsconfig.test.json +0 -12
- package/script/build.ts +0 -65
- package/script/format.ts +0 -7
- package/src/CanadyarnRunner.ts +0 -35
- package/src/CodeStyleChecker.ts +0 -44
- package/src/CoreUtil.ts +0 -24
- package/src/ProjectStructureChecker.ts +0 -119
- package/src/TestRunner.ts +0 -28
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.ts +0 -24
- package/src/WebpackConfigGenerator/Plugin/css.plugin.ts +0 -31
- package/src/WebpackConfigGenerator/Plugin/esbuild.plugin.ts +0 -11
- package/src/WebpackConfigGenerator/Plugin/html.plugin.ts +0 -47
- package/src/WebpackConfigGenerator/Plugin/index.ts +0 -35
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.ts +0 -22
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.ts +0 -29
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.ts +0 -21
- package/src/WebpackConfigGenerator/Rule/index.ts +0 -17
- package/src/WebpackConfigGenerator/Rule/other.rule.ts +0 -23
- package/src/WebpackConfigGenerator/WebpackEntryFactory.ts +0 -22
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.ts +0 -22
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.ts +0 -19
- package/src/WebpackConfigGenerator/index.ts +0 -213
- package/src/WebpackServerStarter.ts +0 -138
- package/src/index.ts +0 -9
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/__snapshots__/shouldIgnore.test.ts.snap +0 -21
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/__snapshots__/shouldTransform.test.ts.snap +0 -53
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/shouldIgnore.test.ts +0 -36
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/shouldTransform.test.ts +0 -72
- package/test/WebpackConfigGenerator/plugin/fixture/script.js +0 -2
- package/test/WebpackConfigGenerator/plugin/fixture/script1.js +0 -1
- package/test/WebpackConfigGenerator/plugin/script-tag-crossorigin-plugin.test.ts +0 -58
- package/test/test-project/package.json +0 -5
- package/tsconfig.json +0 -15
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DynamicPathResolver } from "../type";
|
|
2
|
+
interface WebpackResolveAliasMapOptions {
|
|
3
|
+
env: string | null;
|
|
4
|
+
resolvers: DynamicPathResolver[];
|
|
5
|
+
}
|
|
6
|
+
export declare class WebpackResolveAliasFactory {
|
|
7
|
+
static generate({ env, resolvers }: WebpackResolveAliasMapOptions): {
|
|
8
|
+
[moduleAlias: string]: string;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export {};
|
package/src/WebpackConfigGenerator/{WebpackResolveAliasFactory.ts → WebpackResolveAliasFactory.js}
RENAMED
|
@@ -1,23 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
resolvers
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export class WebpackResolveAliasFactory {
|
|
9
|
-
static generate({env, resolvers}: WebpackResolveAliasMapOptions): {[moduleAlias: string]: string} {
|
|
10
|
-
const moduleAliasMap: {[moduleAlias: string]: string} = {};
|
|
11
|
-
|
|
12
|
-
for (const {prefix, resolver} of resolvers) {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebpackResolveAliasFactory = void 0;
|
|
4
|
+
class WebpackResolveAliasFactory {
|
|
5
|
+
static generate({ env, resolvers }) {
|
|
6
|
+
const moduleAliasMap = {};
|
|
7
|
+
for (const { prefix, resolver } of resolvers) {
|
|
13
8
|
if (prefix in moduleAliasMap) {
|
|
14
9
|
throw new Error(`Duplicated resolver prefix: ${prefix}`);
|
|
15
|
-
}
|
|
10
|
+
}
|
|
11
|
+
else if (prefix.trim() === "") {
|
|
16
12
|
throw new Error(`Resolver prefix cannot be empty`);
|
|
17
|
-
}
|
|
13
|
+
}
|
|
14
|
+
else if (/\s/.test(prefix)) {
|
|
18
15
|
throw new Error(`Resolver prefix cannot contain whitespace, received: ${prefix}`);
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
if (resolver) {
|
|
22
18
|
const resolvedRealPath = typeof resolver === "string" ? resolver : resolver(env);
|
|
23
19
|
if (resolvedRealPath) {
|
|
@@ -25,7 +21,8 @@ export class WebpackResolveAliasFactory {
|
|
|
25
21
|
}
|
|
26
22
|
}
|
|
27
23
|
}
|
|
28
|
-
|
|
29
24
|
return moduleAliasMap;
|
|
30
25
|
}
|
|
31
26
|
}
|
|
27
|
+
exports.WebpackResolveAliasFactory = WebpackResolveAliasFactory;
|
|
28
|
+
//# sourceMappingURL=WebpackResolveAliasFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebpackResolveAliasFactory.js","sourceRoot":"","sources":["../../../src/WebpackConfigGenerator/WebpackResolveAliasFactory.ts"],"names":[],"mappings":";;;AAOA,MAAa,0BAA0B;IACnC,MAAM,CAAC,QAAQ,CAAC,EAAC,GAAG,EAAE,SAAS,EAAgC;QAC3D,MAAM,cAAc,GAAoC,EAAE,CAAC;QAE3D,KAAK,MAAM,EAAC,MAAM,EAAE,QAAQ,EAAC,IAAI,SAAS,EAAE;YACxC,IAAI,MAAM,IAAI,cAAc,EAAE;gBAC1B,MAAM,IAAI,KAAK,CAAC,+BAA+B,MAAM,EAAE,CAAC,CAAC;aAC5D;iBAAM,IAAI,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE;gBAC7B,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;aACtD;iBAAM,IAAI,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;gBAC1B,MAAM,IAAI,KAAK,CAAC,wDAAwD,MAAM,EAAE,CAAC,CAAC;aACrF;YAED,IAAI,QAAQ,EAAE;gBACV,MAAM,gBAAgB,GAAG,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;gBACjF,IAAI,gBAAgB,EAAE;oBAClB,cAAc,CAAC,MAAM,CAAC,GAAG,gBAAgB,CAAC;iBAC7C;aACJ;SACJ;QAED,OAAO,cAAc,CAAC;IAC1B,CAAC;CACJ;AAvBD,gEAuBC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
interface WebpackResolveExtensionsFactoryOptions {
|
|
2
|
+
prioritizedExtensionPrefixes?: string[] | undefined;
|
|
3
|
+
}
|
|
4
|
+
export declare class WebpackResolveExtensionsFactory {
|
|
5
|
+
static generate({ prioritizedExtensionPrefixes }: WebpackResolveExtensionsFactoryOptions): string[];
|
|
6
|
+
}
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebpackResolveExtensionsFactory = void 0;
|
|
4
|
+
const Constant_1 = require("../Constant");
|
|
5
|
+
class WebpackResolveExtensionsFactory {
|
|
6
|
+
static generate({ prioritizedExtensionPrefixes = [] }) {
|
|
7
|
+
const resolveExtensions = [];
|
|
8
|
+
for (const prefix of prioritizedExtensionPrefixes) {
|
|
9
|
+
resolveExtensions.push(...Constant_1.Constant.resolveExtensions.map(_ => `.${prefix}${_}`));
|
|
10
|
+
}
|
|
11
|
+
resolveExtensions.push(...Constant_1.Constant.resolveExtensions);
|
|
12
|
+
return resolveExtensions;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
exports.WebpackResolveExtensionsFactory = WebpackResolveExtensionsFactory;
|
|
16
|
+
//# sourceMappingURL=WebpackResolveExtensionsFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebpackResolveExtensionsFactory.js","sourceRoot":"","sources":["../../../src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.ts"],"names":[],"mappings":";;;AAAA,0CAAqC;AAMrC,MAAa,+BAA+B;IACxC,MAAM,CAAC,QAAQ,CAAC,EAAC,4BAA4B,GAAG,EAAE,EAAyC;QACvF,MAAM,iBAAiB,GAAG,EAAE,CAAC;QAE7B,KAAK,MAAM,MAAM,IAAI,4BAA4B,EAAE;YAC/C,iBAAiB,CAAC,IAAI,CAAC,GAAG,mBAAQ,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;SACpF;QAED,iBAAiB,CAAC,IAAI,CAAC,GAAG,mBAAQ,CAAC,iBAAiB,CAAC,CAAC;QAEtD,OAAO,iBAAiB,CAAC;IAC7B,CAAC;CACJ;AAZD,0EAYC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
static generate({projectSrcDirectory}: WebpackResolveModulesFactoryOptions): string[] {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebpackResolveModulesFactory = void 0;
|
|
4
|
+
class WebpackResolveModulesFactory {
|
|
5
|
+
static generate({ projectSrcDirectory }) {
|
|
7
6
|
const resolveModules = [];
|
|
8
|
-
|
|
9
7
|
/**
|
|
10
8
|
* To let webpack know how to resolve non-relative paths when `tsconfig.json#compilerOptions.baseUrl` is set to "./src"
|
|
11
9
|
* Maybe refactor to a better resolution/aliasing solution later(?)
|
|
@@ -26,13 +24,13 @@ export class WebpackResolveModulesFactory {
|
|
|
26
24
|
* ```
|
|
27
25
|
*/
|
|
28
26
|
resolveModules.push(projectSrcDirectory);
|
|
29
|
-
|
|
30
27
|
/**
|
|
31
28
|
* The default behavior to resolve non-relative paths is by looking inside `node_modules` folder.
|
|
32
29
|
* Put at the end so this has the lowest precedence.
|
|
33
30
|
*/
|
|
34
31
|
resolveModules.push("node_modules");
|
|
35
|
-
|
|
36
32
|
return resolveModules;
|
|
37
33
|
}
|
|
38
34
|
}
|
|
35
|
+
exports.WebpackResolveModulesFactory = WebpackResolveModulesFactory;
|
|
36
|
+
//# sourceMappingURL=WebpackResolveModulesFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebpackResolveModulesFactory.js","sourceRoot":"","sources":["../../../src/WebpackConfigGenerator/WebpackResolveModulesFactory.ts"],"names":[],"mappings":";;;AAIA,MAAa,4BAA4B;IACrC,MAAM,CAAC,QAAQ,CAAC,EAAC,mBAAmB,EAAsC;QACtE,MAAM,cAAc,GAAG,EAAE,CAAC;QAE1B;;;;;;;;;;;;;;;;;;WAkBG;QACH,cAAc,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAEzC;;;WAGG;QACH,cAAc,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAEpC,OAAO,cAAc,CAAC;IAC1B,CAAC;CACJ;AAjCD,oEAiCC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type webpack from "webpack";
|
|
2
|
+
import type { WebpackConfigGeneratorOptions } from "../type";
|
|
3
|
+
/**
|
|
4
|
+
* Generates a webpack config with sane defaults.
|
|
5
|
+
*/
|
|
6
|
+
export declare class WebpackConfigGenerator {
|
|
7
|
+
private readonly options;
|
|
8
|
+
private readonly env;
|
|
9
|
+
private readonly projectDirectory;
|
|
10
|
+
private readonly projectSrcDirectory;
|
|
11
|
+
private readonly tsconfigFilepath;
|
|
12
|
+
private readonly enableProfiling;
|
|
13
|
+
private readonly maxEntryPointKiloByte;
|
|
14
|
+
private readonly maxAssetKiloByte;
|
|
15
|
+
private readonly isFastMode;
|
|
16
|
+
private readonly verbose;
|
|
17
|
+
private readonly defineVars;
|
|
18
|
+
private readonly extraExtensionsForOtherRule;
|
|
19
|
+
private readonly configEntryDescriptors;
|
|
20
|
+
private readonly entry;
|
|
21
|
+
private readonly htmlWebpackPluginInstances;
|
|
22
|
+
private readonly resolveExtensions;
|
|
23
|
+
private readonly resolveModules;
|
|
24
|
+
private readonly resolveAliases;
|
|
25
|
+
private readonly outputPublicPath;
|
|
26
|
+
private readonly logger;
|
|
27
|
+
constructor(options: WebpackConfigGeneratorOptions);
|
|
28
|
+
development(): webpack.Configuration;
|
|
29
|
+
production(outputDirectory: string): webpack.Configuration;
|
|
30
|
+
}
|
|
31
|
+
export type { WebpackConfigGeneratorOptions };
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.WebpackConfigGenerator = void 0;
|
|
7
|
+
const devtool_util_1 = require("@pinnacle0/devtool-util");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const Constant_1 = require("../Constant");
|
|
10
|
+
const CoreUtil_1 = require("../CoreUtil");
|
|
11
|
+
const ConfigEntryDescriptorsFactory_1 = require("./ConfigEntryDescriptorsFactory");
|
|
12
|
+
const HTMLWebpackPluginsFactory_1 = require("./HTMLWebpackPluginsFactory");
|
|
13
|
+
const WebpackConfigSerializationUtil_1 = require("./WebpackConfigSerializationUtil");
|
|
14
|
+
const WebpackEntryFactory_1 = require("./WebpackEntryFactory");
|
|
15
|
+
const WebpackOutputPublicURLFactory_1 = require("./WebpackOutputPublicURLFactory");
|
|
16
|
+
const WebpackResolveAliasFactory_1 = require("./WebpackResolveAliasFactory");
|
|
17
|
+
const WebpackResolveExtensionsFactory_1 = require("./WebpackResolveExtensionsFactory");
|
|
18
|
+
const WebpackResolveModulesFactory_1 = require("./WebpackResolveModulesFactory");
|
|
19
|
+
const Plugin_1 = require("./Plugin");
|
|
20
|
+
const Rule_1 = require("./Rule");
|
|
21
|
+
/**
|
|
22
|
+
* Generates a webpack config with sane defaults.
|
|
23
|
+
*/
|
|
24
|
+
class WebpackConfigGenerator {
|
|
25
|
+
constructor(options) {
|
|
26
|
+
var _a, _b, _c;
|
|
27
|
+
this.options = options;
|
|
28
|
+
this.logger = devtool_util_1.Utility.createConsoleLogger("WebpackConfigGenerator");
|
|
29
|
+
this.env = CoreUtil_1.CoreUtil.currentEnv();
|
|
30
|
+
this.projectDirectory = options.projectDirectory;
|
|
31
|
+
this.projectSrcDirectory = path_1.default.join(options.projectDirectory, "src");
|
|
32
|
+
this.tsconfigFilepath = path_1.default.join(options.projectDirectory, "tsconfig.json");
|
|
33
|
+
this.enableProfiling = CoreUtil_1.CoreUtil.profilingEnabled();
|
|
34
|
+
this.isFastMode = CoreUtil_1.CoreUtil.isFastMode();
|
|
35
|
+
this.maxEntryPointKiloByte = (_a = options.maxEntryPointKiloByte) !== null && _a !== void 0 ? _a : Constant_1.Constant.maxEntryPointKiloByte;
|
|
36
|
+
this.maxAssetKiloByte = (_b = options.maxAssetKiloByte) !== null && _b !== void 0 ? _b : Constant_1.Constant.maxAssetKiloByte;
|
|
37
|
+
this.verbose = options.verbose || false;
|
|
38
|
+
this.defineVars = options.defineVars || {};
|
|
39
|
+
this.extraExtensionsForOtherRule = options.extraExtensionsForOtherRule || [];
|
|
40
|
+
this.configEntryDescriptors = ConfigEntryDescriptorsFactory_1.ConfigEntryDescriptorsFactory.generate({
|
|
41
|
+
indexName: options.indexName || "index",
|
|
42
|
+
projectSrcDirectory: this.projectSrcDirectory,
|
|
43
|
+
extraEntries: options.extraEntries || {},
|
|
44
|
+
});
|
|
45
|
+
this.entry = WebpackEntryFactory_1.WebpackEntryFactory.generate({
|
|
46
|
+
configEntryDescriptors: this.configEntryDescriptors,
|
|
47
|
+
});
|
|
48
|
+
this.htmlWebpackPluginInstances = HTMLWebpackPluginsFactory_1.HTMLWebpackPluginsFactory.generate({
|
|
49
|
+
configEntryDescriptors: this.configEntryDescriptors,
|
|
50
|
+
});
|
|
51
|
+
this.outputPublicPath = WebpackOutputPublicURLFactory_1.WebpackOutputPublicURLFactory.generate({
|
|
52
|
+
env: this.env,
|
|
53
|
+
webpackPublicPath: options.webpackPublicPath,
|
|
54
|
+
});
|
|
55
|
+
this.resolveExtensions = WebpackResolveExtensionsFactory_1.WebpackResolveExtensionsFactory.generate({
|
|
56
|
+
prioritizedExtensionPrefixes: options.prioritizedExtensionPrefixes,
|
|
57
|
+
});
|
|
58
|
+
this.resolveModules = WebpackResolveModulesFactory_1.WebpackResolveModulesFactory.generate({
|
|
59
|
+
projectSrcDirectory: this.projectSrcDirectory,
|
|
60
|
+
});
|
|
61
|
+
this.resolveAliases = WebpackResolveAliasFactory_1.WebpackResolveAliasFactory.generate({
|
|
62
|
+
env: this.env,
|
|
63
|
+
resolvers: (_c = options.dynamicPathResolvers) !== null && _c !== void 0 ? _c : [],
|
|
64
|
+
});
|
|
65
|
+
this.logger.info("Config constructed:");
|
|
66
|
+
for (const info of [
|
|
67
|
+
`-- Code Checking: ${this.isFastMode ? "Minimal Check" : "Default"}`,
|
|
68
|
+
`-- Env: ${this.env || "[N/A]"}`,
|
|
69
|
+
`-- Src Directory: ${this.projectSrcDirectory}`,
|
|
70
|
+
`-- HTML Entries: ${Object.keys(this.entry).join(" / ")}`,
|
|
71
|
+
`-- Webpack Public URL: ${this.outputPublicPath}`,
|
|
72
|
+
`-- Dynamic Aliases: ${JSON.stringify(this.resolveAliases, null, 4)}`,
|
|
73
|
+
`-- Use Cache: ${this.env === null}`,
|
|
74
|
+
]) {
|
|
75
|
+
console.info(info);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
development() {
|
|
79
|
+
const config = {
|
|
80
|
+
mode: "development",
|
|
81
|
+
entry: this.entry,
|
|
82
|
+
target: "web",
|
|
83
|
+
output: {
|
|
84
|
+
filename: "static/js/[name].js",
|
|
85
|
+
publicPath: "/",
|
|
86
|
+
},
|
|
87
|
+
resolve: {
|
|
88
|
+
extensions: this.resolveExtensions,
|
|
89
|
+
modules: this.resolveModules,
|
|
90
|
+
alias: this.resolveAliases,
|
|
91
|
+
},
|
|
92
|
+
devtool: "inline-cheap-module-source-map",
|
|
93
|
+
optimization: {
|
|
94
|
+
usedExports: true,
|
|
95
|
+
splitChunks: {
|
|
96
|
+
automaticNameDelimiter: "-",
|
|
97
|
+
maxAsyncRequests: 30,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
module: {
|
|
101
|
+
rules: [
|
|
102
|
+
Rule_1.Rule.ts({ tsconfigFilepath: this.tsconfigFilepath, transpileOnly: true, fastRefresh: true }),
|
|
103
|
+
Rule_1.Rule.stylesheet({ minimize: false }),
|
|
104
|
+
Rule_1.Rule.image(),
|
|
105
|
+
Rule_1.Rule.other({ extraExtensionsForOtherRule: this.extraExtensionsForOtherRule }),
|
|
106
|
+
// prettier-format-preserve
|
|
107
|
+
],
|
|
108
|
+
},
|
|
109
|
+
plugins: [
|
|
110
|
+
...this.htmlWebpackPluginInstances,
|
|
111
|
+
Plugin_1.Plugin.ignoreMomentLocale(),
|
|
112
|
+
Plugin_1.Plugin.reactRefresh(),
|
|
113
|
+
Plugin_1.Plugin.webpack.progress({ enableProfiling: false }),
|
|
114
|
+
Plugin_1.Plugin.webpack.define(this.defineVars),
|
|
115
|
+
// prettier-format-preserve
|
|
116
|
+
],
|
|
117
|
+
cache: this.env === null
|
|
118
|
+
? {
|
|
119
|
+
type: "filesystem",
|
|
120
|
+
cacheDirectory: path_1.default.join(this.projectDirectory, ".webpack-cache"),
|
|
121
|
+
}
|
|
122
|
+
: false,
|
|
123
|
+
};
|
|
124
|
+
if (this.verbose || CoreUtil_1.CoreUtil.verbose()) {
|
|
125
|
+
this.logger.info("Full webpack config:");
|
|
126
|
+
console.info(WebpackConfigSerializationUtil_1.WebpackConfigSerializationUtil.configToString(config));
|
|
127
|
+
}
|
|
128
|
+
return config;
|
|
129
|
+
}
|
|
130
|
+
production(outputDirectory) {
|
|
131
|
+
const config = {
|
|
132
|
+
mode: "production",
|
|
133
|
+
entry: this.entry,
|
|
134
|
+
target: ["web", "es5"],
|
|
135
|
+
output: {
|
|
136
|
+
path: outputDirectory,
|
|
137
|
+
filename: this.enableProfiling ? "static/js/[name].js" : pathInfo => this.configEntryDescriptors.find(_ => _.name === pathInfo.chunk.name).outputFilename,
|
|
138
|
+
chunkFilename: this.enableProfiling ? "static/js/[id].[name].js" : "static/js/[id].[chunkhash:8].js",
|
|
139
|
+
publicPath: this.outputPublicPath,
|
|
140
|
+
crossOriginLoading: "anonymous",
|
|
141
|
+
},
|
|
142
|
+
resolve: {
|
|
143
|
+
extensions: this.resolveExtensions,
|
|
144
|
+
modules: this.resolveModules,
|
|
145
|
+
alias: this.resolveAliases,
|
|
146
|
+
},
|
|
147
|
+
bail: true,
|
|
148
|
+
optimization: {
|
|
149
|
+
splitChunks: {
|
|
150
|
+
automaticNameDelimiter: "-",
|
|
151
|
+
maxAsyncRequests: 30,
|
|
152
|
+
},
|
|
153
|
+
minimizer: [
|
|
154
|
+
Plugin_1.Plugin.minimizer.terser({ sourceMap: true }),
|
|
155
|
+
Plugin_1.Plugin.minimizer.esbuildMinimizer(),
|
|
156
|
+
// prettier-format-preserve
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
performance: {
|
|
160
|
+
maxEntrypointSize: this.enableProfiling ? Number.MAX_SAFE_INTEGER : this.maxEntryPointKiloByte * 1000,
|
|
161
|
+
maxAssetSize: this.maxAssetKiloByte * 1000,
|
|
162
|
+
assetFilter: (filename) => Constant_1.Constant.mediaExtensions.every(_ => !filename.endsWith(_)),
|
|
163
|
+
},
|
|
164
|
+
module: {
|
|
165
|
+
rules: [
|
|
166
|
+
Rule_1.Rule.ts({ tsconfigFilepath: this.tsconfigFilepath, transpileOnly: false, fastRefresh: false }),
|
|
167
|
+
Rule_1.Rule.stylesheet({ minimize: true }),
|
|
168
|
+
Rule_1.Rule.image(),
|
|
169
|
+
Rule_1.Rule.other({ extraExtensionsForOtherRule: this.extraExtensionsForOtherRule }),
|
|
170
|
+
// prettier-format-preserve
|
|
171
|
+
],
|
|
172
|
+
},
|
|
173
|
+
plugins: [
|
|
174
|
+
...this.htmlWebpackPluginInstances,
|
|
175
|
+
Plugin_1.Plugin.scriptTagCrossOriginPlugin(),
|
|
176
|
+
Plugin_1.Plugin.ignoreMomentLocale(),
|
|
177
|
+
Plugin_1.Plugin.fileOutput.miniCssExtract({ enableProfiling: this.enableProfiling }),
|
|
178
|
+
...(this.enableProfiling ? [Plugin_1.Plugin.webpack.progress({ enableProfiling: true })] : []),
|
|
179
|
+
Plugin_1.Plugin.webpack.define(this.defineVars),
|
|
180
|
+
// prettier-format-preserve
|
|
181
|
+
],
|
|
182
|
+
};
|
|
183
|
+
if (this.verbose || CoreUtil_1.CoreUtil.verbose()) {
|
|
184
|
+
this.logger.info("Full webpack config:");
|
|
185
|
+
console.info(WebpackConfigSerializationUtil_1.WebpackConfigSerializationUtil.configToString(config));
|
|
186
|
+
}
|
|
187
|
+
return config;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.WebpackConfigGenerator = WebpackConfigGenerator;
|
|
191
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/WebpackConfigGenerator/index.ts"],"names":[],"mappings":";;;;;;AAAA,0DAAgD;AAChD,gDAAwB;AAExB,0CAAqC;AACrC,0CAAqC;AAErC,mFAA8E;AAC9E,2EAAsE;AACtE,qFAAgF;AAChF,+DAA0D;AAC1D,mFAA8E;AAC9E,6EAAwE;AACxE,uFAAkF;AAClF,iFAA4E;AAC5E,qCAAgC;AAChC,iCAA4B;AAE5B;;GAEG;AACH,MAAa,sBAAsB;IAuB/B,YAA6B,OAAsC;;QAAtC,YAAO,GAAP,OAAO,CAA+B;QAFlD,WAAM,GAAG,sBAAO,CAAC,mBAAmB,CAAC,wBAAwB,CAAC,CAAC;QAG5E,IAAI,CAAC,GAAG,GAAG,mBAAQ,CAAC,UAAU,EAAE,CAAC;QACjC,IAAI,CAAC,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;QACjD,IAAI,CAAC,mBAAmB,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,KAAK,CAAC,CAAC;QACtE,IAAI,CAAC,gBAAgB,GAAG,cAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;QAE7E,IAAI,CAAC,eAAe,GAAG,mBAAQ,CAAC,gBAAgB,EAAE,CAAC;QACnD,IAAI,CAAC,UAAU,GAAG,mBAAQ,CAAC,UAAU,EAAE,CAAC;QACxC,IAAI,CAAC,qBAAqB,GAAG,MAAA,OAAO,CAAC,qBAAqB,mCAAI,mBAAQ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@@
|
|
|
1
|
+
import type { Application as ExpressApplication } from "express";
|
|
2
|
+
import type { WebpackConfigGeneratorOptions } from "./WebpackConfigGenerator";
|
|
3
|
+
export interface WebpackServerStarterOptions extends Pick<WebpackConfigGeneratorOptions, "projectDirectory" | "dynamicPathResolvers" | "extraEntries" | "prioritizedExtensionPrefixes" | "defineVars" | "extraExtensionsForOtherRule"> {
|
|
4
|
+
port: number;
|
|
5
|
+
apiProxy?: {
|
|
6
|
+
target: string;
|
|
7
|
+
context: string[];
|
|
8
|
+
};
|
|
9
|
+
interceptExpressApp?: (app: ExpressApplication) => void;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Start webpack dev server, by creating WebpackServerStarter instance and then run.
|
|
13
|
+
*
|
|
14
|
+
***************************************
|
|
15
|
+
*
|
|
16
|
+
* Add "--env envName" to command line, if you want to switch config folder dynamically.
|
|
17
|
+
*/
|
|
18
|
+
export declare class WebpackServerStarter {
|
|
19
|
+
private readonly devServerConfigContentBase;
|
|
20
|
+
private readonly onBeforeSetupMiddleware;
|
|
21
|
+
private readonly port;
|
|
22
|
+
private readonly apiProxy;
|
|
23
|
+
private readonly logger;
|
|
24
|
+
private readonly webpackConfig;
|
|
25
|
+
constructor({ projectDirectory, port, apiProxy, interceptExpressApp, dynamicPathResolvers, extraEntries, prioritizedExtensionPrefixes, defineVars, extraExtensionsForOtherRule, }: WebpackServerStarterOptions);
|
|
26
|
+
run(): Promise<void>;
|
|
27
|
+
private createDevServerInstance;
|
|
28
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.WebpackServerStarter = void 0;
|
|
16
|
+
const devtool_util_1 = require("@pinnacle0/devtool-util");
|
|
17
|
+
const path_1 = __importDefault(require("path"));
|
|
18
|
+
const webpack_1 = __importDefault(require("webpack"));
|
|
19
|
+
const webpack_dev_server_1 = __importDefault(require("webpack-dev-server"));
|
|
20
|
+
const WebpackConfigGenerator_1 = require("./WebpackConfigGenerator");
|
|
21
|
+
/**
|
|
22
|
+
* Start webpack dev server, by creating WebpackServerStarter instance and then run.
|
|
23
|
+
*
|
|
24
|
+
***************************************
|
|
25
|
+
*
|
|
26
|
+
* Add "--env envName" to command line, if you want to switch config folder dynamically.
|
|
27
|
+
*/
|
|
28
|
+
class WebpackServerStarter {
|
|
29
|
+
constructor({ projectDirectory, port, apiProxy, interceptExpressApp, dynamicPathResolvers, extraEntries, prioritizedExtensionPrefixes, defineVars, extraExtensionsForOtherRule, }) {
|
|
30
|
+
this.logger = devtool_util_1.Utility.createConsoleLogger("WebpackServerStarter");
|
|
31
|
+
this.devServerConfigContentBase = path_1.default.join(projectDirectory, "static");
|
|
32
|
+
this.port = port;
|
|
33
|
+
this.apiProxy = apiProxy
|
|
34
|
+
? [
|
|
35
|
+
{
|
|
36
|
+
context: apiProxy.context,
|
|
37
|
+
target: apiProxy.target,
|
|
38
|
+
secure: false,
|
|
39
|
+
changeOrigin: true,
|
|
40
|
+
},
|
|
41
|
+
]
|
|
42
|
+
: undefined;
|
|
43
|
+
this.onBeforeSetupMiddleware = interceptExpressApp ? devServer => (devServer.app ? interceptExpressApp(devServer.app) : undefined) : undefined;
|
|
44
|
+
this.webpackConfig = new WebpackConfigGenerator_1.WebpackConfigGenerator({
|
|
45
|
+
projectDirectory,
|
|
46
|
+
dynamicPathResolvers,
|
|
47
|
+
extraEntries,
|
|
48
|
+
prioritizedExtensionPrefixes,
|
|
49
|
+
defineVars,
|
|
50
|
+
extraExtensionsForOtherRule,
|
|
51
|
+
}).development();
|
|
52
|
+
}
|
|
53
|
+
run() {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
try {
|
|
56
|
+
this.logger.info(["Starting dev server on port", String(this.port)]);
|
|
57
|
+
const server = this.createDevServerInstance();
|
|
58
|
+
const signals = ["SIGINT", "SIGTERM"];
|
|
59
|
+
for (const signal of signals) {
|
|
60
|
+
process.on(signal, () => {
|
|
61
|
+
// force stop webpack dev server
|
|
62
|
+
server.stopCallback(() => { });
|
|
63
|
+
process.exit();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
yield server.start();
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
this.logger.error(e);
|
|
70
|
+
console.error(e);
|
|
71
|
+
process.exit(1);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
createDevServerInstance() {
|
|
76
|
+
return new webpack_dev_server_1.default({
|
|
77
|
+
host: "0.0.0.0",
|
|
78
|
+
port: this.port,
|
|
79
|
+
static: {
|
|
80
|
+
directory: this.devServerConfigContentBase,
|
|
81
|
+
},
|
|
82
|
+
historyApiFallback: true,
|
|
83
|
+
server: {
|
|
84
|
+
type: "https",
|
|
85
|
+
},
|
|
86
|
+
compress: true,
|
|
87
|
+
hot: true,
|
|
88
|
+
client: {
|
|
89
|
+
overlay: {
|
|
90
|
+
errors: true,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
onBeforeSetupMiddleware: this.onBeforeSetupMiddleware,
|
|
94
|
+
devMiddleware: {
|
|
95
|
+
stats: {
|
|
96
|
+
colors: true,
|
|
97
|
+
// https://github.com/webpack/webpack/blob/b65d060040a26255cbf6f50350fef4d4ffcce4d7/lib/stats/DefaultStatsPresetPlugin.js#L96-L103
|
|
98
|
+
all: false,
|
|
99
|
+
errors: true,
|
|
100
|
+
errorsCount: true,
|
|
101
|
+
warnings: true,
|
|
102
|
+
warningsCount: true,
|
|
103
|
+
logging: "warn",
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
proxy: this.apiProxy,
|
|
107
|
+
}, (0, webpack_1.default)(this.webpackConfig));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.WebpackServerStarter = WebpackServerStarter;
|
|
111
|
+
//# sourceMappingURL=WebpackServerStarter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebpackServerStarter.js","sourceRoot":"","sources":["../../src/WebpackServerStarter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0DAAgD;AAChD,gDAAwB;AACxB,sDAA8B;AAC9B,4EAA2C;AAG3C,qEAAgE;AAiBhE;;;;;;GAMG;AAEH,MAAa,oBAAoB;IAe7B,YAAY,EACR,gBAAgB,EAChB,IAAI,EACJ,QAAQ,EACR,mBAAmB,EACnB,oBAAoB,EACpB,YAAY,EACZ,4BAA4B,EAC5B,UAAU,EACV,2BAA2B,GACD;QAbb,WAAM,GAAG,sBAAO,CAAC,mBAAmB,CAAC,sBAAsB,CAAC,CAAC;QAc1E,IAAI,CAAC,0BAA0B,GAAG,cAAI,CAAC,IAAI,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC;QACxE,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ;YACpB,CAAC,CAAC;gBACI;oBACI,OAAO,EAAE,QAAQ,CAAC,OAAO;oBACzB,MAAM,EAAE,QAAQ,CAAC,MAAM;oBACvB,MAAM,EAAE,KAAK;oBACb,YAAY,EAAE,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uBAAuB;QAC3B,OAAO,IAAI,4BAAS,CAChB;YACI,IAAI,EAAE,SAAS;YACf,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,MAAM,EAAE;gBACJ,SAAS,EAAE,IAAI,CAAC,0BAA0B;aAC7C;YACD,kBAAkB,EAAE,IAAI;YACxB,MAAM,EAAE;gBACJ,IAAI,EAAE,OAAO;aAChB;YACD,QAAQ,EAAE,IAAI;YACd,GAAG,EAAE,IAAI;YACT,MAAM,EAAE;gBACJ,OAAO,EAAE;oBACL,MAAM,EAAE,IAAI;iBACf;aACJ;YACD,uBAAuB,EAAE,IAAI,CAAC,uBAAuB;YACrD,aAAa,EAAE;gBACX,KAAK,EAAE;oBACH,MAAM,EAAE,IAAI;oBACZ,kIAAkI;oBAClI,GAAG,EAAE,KAAK;oBACV,MAAM,EAAE,IAAI;oBACZ,WAAW,EAAE,IAAI;oBACjB,QAAQ,EAAE,IAAI;oBACd,aAAa,EAAE,IAAI;oBACnB,OAAO,EAAE,MAAM;iBAClB;aACJ;YACD,KAAK,EAAE,IAAI,CAAC,QAAQ;SACvB,EACD,IAAA,iBAAO,EAAC,IAAI,CAAC,aAAa,CAAC,CAC9B,CAAC;IACN,CAAC;CACJ;AA1GD,oDA0GC"}
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WebpackBuilder } from "./WebpackBuilder";
|
|
2
|
+
import { WebpackServerStarter } from "./WebpackServerStarter";
|
|
3
|
+
export declare const WebpackUtil: Readonly<{
|
|
4
|
+
currentEnv: () => string | null;
|
|
5
|
+
profilingEnabled: () => boolean;
|
|
6
|
+
isFastMode: () => boolean;
|
|
7
|
+
verbose: () => boolean;
|
|
8
|
+
Builder: typeof WebpackBuilder;
|
|
9
|
+
ServerStarter: typeof WebpackServerStarter;
|
|
10
|
+
}>;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebpackUtil = void 0;
|
|
4
|
+
const WebpackBuilder_1 = require("./WebpackBuilder");
|
|
5
|
+
const WebpackServerStarter_1 = require("./WebpackServerStarter");
|
|
6
|
+
const CoreUtil_1 = require("./CoreUtil");
|
|
7
|
+
exports.WebpackUtil = Object.freeze(Object.assign({ Builder: WebpackBuilder_1.WebpackBuilder, ServerStarter: WebpackServerStarter_1.WebpackServerStarter }, CoreUtil_1.CoreUtil));
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAgD;AAChD,iEAA4D;AAC5D,yCAAoC;AAEvB,QAAA,WAAW,GAAG,MAAM,CAAC,MAAM,iBACpC,OAAO,EAAE,+BAAc,EACvB,aAAa,EAAE,2CAAoB,IAChC,mBAAQ,EACb,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type webpack from "webpack";
|
|
2
|
-
|
|
3
2
|
export interface WebpackConfigGeneratorOptions {
|
|
4
3
|
/**
|
|
5
4
|
* Directory of containing the application code.
|
|
@@ -89,11 +88,12 @@ export interface WebpackConfigGeneratorOptions {
|
|
|
89
88
|
/**
|
|
90
89
|
* Ref: https://webpack.js.org/plugins/define-plugin/
|
|
91
90
|
*/
|
|
92
|
-
defineVars?: {
|
|
91
|
+
defineVars?: {
|
|
92
|
+
[key: string]: string;
|
|
93
|
+
} | undefined;
|
|
93
94
|
onSuccess?: () => void;
|
|
94
95
|
extraExtensionsForOtherRule?: string[] | undefined;
|
|
95
96
|
}
|
|
96
|
-
|
|
97
97
|
export interface EntryDescriptor {
|
|
98
98
|
name: string;
|
|
99
99
|
/**
|
|
@@ -114,7 +114,6 @@ export interface EntryDescriptor {
|
|
|
114
114
|
*/
|
|
115
115
|
htmlPath?: string;
|
|
116
116
|
}
|
|
117
|
-
|
|
118
117
|
/**
|
|
119
118
|
* Same as EntryDescriptor, but guaranteed to have an htmlPath.
|
|
120
119
|
* Used for creating HTMLWebpackPlugin instances.
|
|
@@ -125,7 +124,6 @@ export interface HTMLEntryDescriptor {
|
|
|
125
124
|
entryPath: string;
|
|
126
125
|
htmlPath: string;
|
|
127
126
|
}
|
|
128
|
-
|
|
129
127
|
export interface DynamicPathResolver {
|
|
130
128
|
/**
|
|
131
129
|
* Prefix of the dependencies that should be aliased.
|
|
@@ -144,7 +142,6 @@ export interface DynamicPathResolver {
|
|
|
144
142
|
*/
|
|
145
143
|
resolver: string | null | ((env: string | null) => string | null);
|
|
146
144
|
}
|
|
147
|
-
|
|
148
145
|
export interface InternalCheckerOptions {
|
|
149
146
|
/**
|
|
150
147
|
* Directory of containing the application code.
|
|
@@ -163,7 +160,6 @@ export interface InternalCheckerOptions {
|
|
|
163
160
|
*/
|
|
164
161
|
extraCheckDirectories?: string[];
|
|
165
162
|
}
|
|
166
|
-
|
|
167
163
|
declare module "webpack" {
|
|
168
164
|
interface TapablePlugin {
|
|
169
165
|
apply(...args: any[]): void;
|
|
@@ -180,7 +176,7 @@ declare module "webpack" {
|
|
|
180
176
|
* This is a workaround to allow "@types/*-plugin" packages to work before their
|
|
181
177
|
* type definitions are properly upgraded.
|
|
182
178
|
*/
|
|
183
|
-
|
|
179
|
+
abstract class Plugin {
|
|
184
180
|
apply(compiler: webpack.Compiler): void;
|
|
185
181
|
}
|
|
186
182
|
}
|
package/src/type.js
ADDED
package/src/type.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/type.ts"],"names":[],"mappings":""}
|
package/config/jest.config.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type {Config} from "@jest/types";
|
|
2
|
-
|
|
3
|
-
const config: Config.InitialOptionsWithRootDir = {
|
|
4
|
-
// Stop running tests after `n` failures
|
|
5
|
-
bail: 1,
|
|
6
|
-
|
|
7
|
-
// A preset that is used as a base for Jest's configuration
|
|
8
|
-
preset: "ts-jest",
|
|
9
|
-
|
|
10
|
-
// A set of global variables that need to be available in all test environments
|
|
11
|
-
globals: {
|
|
12
|
-
"ts-jest": {
|
|
13
|
-
tsconfig: "<rootDir>/config/tsconfig.test.json",
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
|
|
17
|
-
// The root directory that Jest should scan for tests and modules within
|
|
18
|
-
rootDir: "../",
|
|
19
|
-
|
|
20
|
-
// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
|
|
21
|
-
testPathIgnorePatterns: ["/node_modules/", "<rootDir>/build/"],
|
|
22
|
-
|
|
23
|
-
// A map from regular expressions to paths to transformers
|
|
24
|
-
transform: {
|
|
25
|
-
[String.raw`\.(ts|tsx)$`]: "ts-jest",
|
|
26
|
-
},
|
|
27
|
-
|
|
28
|
-
// Indicates whether each individual test should be reported during the run
|
|
29
|
-
verbose: true,
|
|
30
|
-
|
|
31
|
-
// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
|
|
32
|
-
watchPathIgnorePatterns: ["<rootDir>/build/", "dist/"],
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
export default config;
|