@pinnacle0/webpack-util 0.3.23 → 0.3.26
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/config/jest.config.ts +35 -0
- package/config/tsconfig.script.json +10 -0
- package/config/tsconfig.src.json +12 -0
- package/config/tsconfig.test.json +11 -0
- package/package.json +6 -8
- package/script/build.ts +65 -0
- package/script/format.ts +7 -0
- package/src/CanadyarnRunner.ts +35 -0
- package/src/CodeStyleChecker.ts +44 -0
- package/src/{Constant.js → Constant.ts} +1 -5
- package/src/CoreUtil.ts +24 -0
- package/src/ProjectStructureChecker.ts +119 -0
- package/src/TestRunner.ts +28 -0
- package/src/TypescriptTypeChecker.ts +29 -0
- package/src/{WebpackBuilder.js → WebpackBuilder.ts} +71 -51
- package/src/WebpackConfigGenerator/{ConfigEntryDescriptorsFactory.js → ConfigEntryDescriptorsFactory.ts} +36 -29
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.ts +24 -0
- package/src/WebpackConfigGenerator/Plugin/css.plugin.ts +31 -0
- package/src/WebpackConfigGenerator/Plugin/html.plugin.ts +47 -0
- package/src/WebpackConfigGenerator/Plugin/index.ts +33 -0
- package/src/WebpackConfigGenerator/Plugin/{moment.plugin.js → moment.plugin.ts} +5 -12
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.ts +22 -0
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.ts +29 -0
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.ts +21 -0
- package/src/WebpackConfigGenerator/Rule/{RegExpUtil.js → RegExpUtil.ts} +8 -14
- package/src/WebpackConfigGenerator/Rule/{core-fe-hmr-babel-plugin.js → core-fe-hmr-babel-plugin.ts} +43 -9
- package/src/WebpackConfigGenerator/Rule/{image.rule.js → image.rule.ts} +5 -8
- package/src/WebpackConfigGenerator/Rule/index.ts +17 -0
- package/src/WebpackConfigGenerator/Rule/other.rule.ts +23 -0
- package/src/WebpackConfigGenerator/Rule/{stylesheet.rule.js → stylesheet.rule.ts} +34 -30
- package/src/WebpackConfigGenerator/Rule/{ts.rule.js → ts.rule.ts} +19 -17
- package/src/WebpackConfigGenerator/{WebpackConfigSerializationUtil.js → WebpackConfigSerializationUtil.ts} +23 -22
- package/src/WebpackConfigGenerator/WebpackEntryFactory.ts +22 -0
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.ts +22 -0
- package/src/WebpackConfigGenerator/{WebpackResolveAliasFactory.js → WebpackResolveAliasFactory.ts} +16 -13
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.ts +19 -0
- package/src/WebpackConfigGenerator/{WebpackResolveModulesFactory.js → WebpackResolveModulesFactory.ts} +9 -7
- package/src/WebpackConfigGenerator/index.ts +213 -0
- package/src/WebpackServerStarter.ts +138 -0
- package/src/index.ts +9 -0
- package/src/{type.d.ts → type.ts} +8 -4
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/__snapshots__/shouldIgnore.test.ts.snap +21 -0
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/__snapshots__/shouldTransform.test.ts.snap +53 -0
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/shouldIgnore.test.ts +36 -0
- package/test/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin/shouldTransform.test.ts +72 -0
- package/test/WebpackConfigGenerator/plugin/fixture/script.js +2 -0
- package/test/WebpackConfigGenerator/plugin/fixture/script1.js +1 -0
- package/test/WebpackConfigGenerator/plugin/script-tag-crossorigin-plugin.test.ts +58 -0
- package/test/test-project/package.json +5 -0
- package/tsconfig.json +15 -0
- package/src/CanadyarnRunner.d.ts +0 -14
- package/src/CanadyarnRunner.js +0 -38
- package/src/CanadyarnRunner.js.map +0 -1
- package/src/CodeStyleChecker.d.ts +0 -10
- package/src/CodeStyleChecker.js +0 -44
- package/src/CodeStyleChecker.js.map +0 -1
- package/src/Constant.d.ts +0 -21
- package/src/Constant.js.map +0 -1
- package/src/CoreUtil.d.ts +0 -11
- package/src/CoreUtil.js +0 -26
- package/src/CoreUtil.js.map +0 -1
- package/src/ProjectStructureChecker.d.ts +0 -18
- package/src/ProjectStructureChecker.js +0 -113
- package/src/ProjectStructureChecker.js.map +0 -1
- package/src/TestRunner.d.ts +0 -8
- package/src/TestRunner.js +0 -30
- package/src/TestRunner.js.map +0 -1
- package/src/TypescriptTypeChecker.d.ts +0 -8
- package/src/TypescriptTypeChecker.js +0 -25
- package/src/TypescriptTypeChecker.js.map +0 -1
- package/src/WebpackBuilder.d.ts +0 -38
- package/src/WebpackBuilder.js.map +0 -1
- package/src/WebpackConfigGenerator/ConfigEntryDescriptorsFactory.d.ts +0 -13
- package/src/WebpackConfigGenerator/ConfigEntryDescriptorsFactory.js.map +0 -1
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.d.ts +0 -9
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.js +0 -20
- package/src/WebpackConfigGenerator/HTMLWebpackPluginsFactory.js.map +0 -1
- package/src/WebpackConfigGenerator/Plugin/css.plugin.d.ts +0 -16
- package/src/WebpackConfigGenerator/Plugin/css.plugin.js +0 -33
- package/src/WebpackConfigGenerator/Plugin/css.plugin.js.map +0 -1
- package/src/WebpackConfigGenerator/Plugin/html.plugin.d.ts +0 -16
- package/src/WebpackConfigGenerator/Plugin/html.plugin.js +0 -48
- package/src/WebpackConfigGenerator/Plugin/html.plugin.js.map +0 -1
- package/src/WebpackConfigGenerator/Plugin/index.d.ts +0 -27
- package/src/WebpackConfigGenerator/Plugin/index.js +0 -32
- package/src/WebpackConfigGenerator/Plugin/index.js.map +0 -1
- package/src/WebpackConfigGenerator/Plugin/moment.plugin.d.ts +0 -10
- package/src/WebpackConfigGenerator/Plugin/moment.plugin.js.map +0 -1
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.d.ts +0 -4
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.js +0 -28
- package/src/WebpackConfigGenerator/Plugin/script-tag-crossorigin-plugin.js.map +0 -1
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.d.ts +0 -16
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.js +0 -31
- package/src/WebpackConfigGenerator/Plugin/ts.plugin.js.map +0 -1
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.d.ts +0 -14
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.js +0 -24
- package/src/WebpackConfigGenerator/Plugin/webpack.plugin.js.map +0 -1
- package/src/WebpackConfigGenerator/Rule/RegExpUtil.d.ts +0 -4
- package/src/WebpackConfigGenerator/Rule/RegExpUtil.js.map +0 -1
- package/src/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin.d.ts +0 -13
- package/src/WebpackConfigGenerator/Rule/core-fe-hmr-babel-plugin.js.map +0 -1
- package/src/WebpackConfigGenerator/Rule/image.rule.d.ts +0 -9
- package/src/WebpackConfigGenerator/Rule/image.rule.js.map +0 -1
- package/src/WebpackConfigGenerator/Rule/index.d.ts +0 -13
- package/src/WebpackConfigGenerator/Rule/index.js +0 -18
- package/src/WebpackConfigGenerator/Rule/index.js.map +0 -1
- package/src/WebpackConfigGenerator/Rule/other.rule.d.ts +0 -12
- package/src/WebpackConfigGenerator/Rule/other.rule.js +0 -22
- package/src/WebpackConfigGenerator/Rule/other.rule.js.map +0 -1
- package/src/WebpackConfigGenerator/Rule/stylesheet.rule.d.ts +0 -17
- package/src/WebpackConfigGenerator/Rule/stylesheet.rule.js.map +0 -1
- package/src/WebpackConfigGenerator/Rule/ts.rule.d.ts +0 -18
- package/src/WebpackConfigGenerator/Rule/ts.rule.js.map +0 -1
- package/src/WebpackConfigGenerator/WebpackConfigSerializationUtil.d.ts +0 -10
- package/src/WebpackConfigGenerator/WebpackConfigSerializationUtil.js.map +0 -1
- package/src/WebpackConfigGenerator/WebpackEntryFactory.d.ts +0 -9
- package/src/WebpackConfigGenerator/WebpackEntryFactory.js +0 -14
- package/src/WebpackConfigGenerator/WebpackEntryFactory.js.map +0 -1
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.d.ts +0 -11
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.js +0 -16
- package/src/WebpackConfigGenerator/WebpackOutputPublicURLFactory.js.map +0 -1
- package/src/WebpackConfigGenerator/WebpackResolveAliasFactory.d.ts +0 -11
- package/src/WebpackConfigGenerator/WebpackResolveAliasFactory.js.map +0 -1
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.d.ts +0 -7
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.js +0 -16
- package/src/WebpackConfigGenerator/WebpackResolveExtensionsFactory.js.map +0 -1
- package/src/WebpackConfigGenerator/WebpackResolveModulesFactory.d.ts +0 -7
- package/src/WebpackConfigGenerator/WebpackResolveModulesFactory.js.map +0 -1
- package/src/WebpackConfigGenerator/index.d.ts +0 -31
- package/src/WebpackConfigGenerator/index.js +0 -191
- package/src/WebpackConfigGenerator/index.js.map +0 -1
- package/src/WebpackServerStarter.d.ts +0 -28
- package/src/WebpackServerStarter.js +0 -111
- package/src/WebpackServerStarter.js.map +0 -1
- package/src/index.d.ts +0 -10
- package/src/index.js +0 -8
- package/src/index.js.map +0 -1
- package/src/type.js +0 -3
- package/src/type.js.map +0 -1
package/src/WebpackConfigGenerator/Rule/{core-fe-hmr-babel-plugin.js → core-fe-hmr-babel-plugin.ts}
RENAMED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import type * as babel from "@babel/core";
|
|
2
|
+
|
|
3
|
+
interface State extends Pick<babel.PluginPass, "file" | "key" | "opts" | "cwd" | "filename"> {
|
|
4
|
+
hasInjectedDeclineWebpackHMRNode: boolean;
|
|
5
|
+
}
|
|
6
|
+
|
|
3
7
|
/**
|
|
4
8
|
* Injects `if (module.hot) module.hot.decline()` code snippet in files that contains "core-fe" Module classes.
|
|
5
9
|
*
|
|
@@ -7,39 +11,68 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
11
|
* otherwise react loses refrence of the MainComponent created by `ModuleProxy` in "core-fe"
|
|
8
12
|
* and throws a runtime error during development (which is bad for developer experience).
|
|
9
13
|
*/
|
|
10
|
-
function
|
|
14
|
+
export default function ({types: t}: typeof babel): babel.PluginObj<State> {
|
|
11
15
|
return {
|
|
12
16
|
visitor: {
|
|
13
17
|
ImportDeclaration(path, state) {
|
|
14
18
|
if (state.hasInjectedDeclineWebpackHMRNode) {
|
|
15
19
|
return;
|
|
16
20
|
}
|
|
17
|
-
|
|
21
|
+
|
|
22
|
+
const {
|
|
23
|
+
node: {
|
|
24
|
+
source: {value: importSource},
|
|
25
|
+
specifiers: importSpecifiers,
|
|
26
|
+
},
|
|
27
|
+
} = path;
|
|
28
|
+
|
|
18
29
|
if (importSource !== "core-fe") {
|
|
19
30
|
return;
|
|
20
31
|
}
|
|
32
|
+
|
|
21
33
|
if (!hasImportSpecifierOfIdentifierModule(t, importSpecifiers)) {
|
|
22
34
|
return;
|
|
23
35
|
}
|
|
36
|
+
|
|
24
37
|
// We now know the TS/JS file has included `Module`, inject the code snippet
|
|
25
|
-
const programPath = path.findParent(parentPath => t.isProgram(parentPath.node))
|
|
38
|
+
const programPath = path.findParent(parentPath => t.isProgram(parentPath.node))! as babel.NodePath<babel.types.Program>;
|
|
39
|
+
|
|
26
40
|
// prettier-ignore
|
|
27
|
-
const declineWebpackHMRNode = t.ifStatement(
|
|
41
|
+
const declineWebpackHMRNode = t.ifStatement(
|
|
42
|
+
t.memberExpression(
|
|
43
|
+
t.identifier("module"),
|
|
44
|
+
t.identifier("hot")
|
|
45
|
+
),
|
|
46
|
+
t.expressionStatement(
|
|
47
|
+
t.callExpression(
|
|
48
|
+
t.memberExpression(
|
|
49
|
+
t.memberExpression(
|
|
50
|
+
t.identifier("module"),
|
|
51
|
+
t.identifier("hot"),
|
|
52
|
+
),
|
|
53
|
+
t.identifier("decline"),
|
|
54
|
+
),
|
|
55
|
+
[],
|
|
56
|
+
),
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
|
|
28
60
|
// Append `if (module.hot) module.hot.decline()` to end of program body
|
|
29
61
|
programPath.pushContainer("body", declineWebpackHMRNode);
|
|
62
|
+
|
|
30
63
|
// We only need to inject the code snippet once per file, mark as injected
|
|
31
64
|
state.hasInjectedDeclineWebpackHMRNode = true;
|
|
32
65
|
},
|
|
33
66
|
},
|
|
34
67
|
};
|
|
35
68
|
}
|
|
36
|
-
|
|
69
|
+
|
|
37
70
|
/**
|
|
38
71
|
* @param t `babel.types`
|
|
39
72
|
* @param importSpecifiers The "specifier" property of a `babel.types.ImportDeclaration` node
|
|
40
73
|
* @returns true if the import declaration includes the identifier `Module`
|
|
41
74
|
*/
|
|
42
|
-
function hasImportSpecifierOfIdentifierModule(t, importSpecifiers) {
|
|
75
|
+
function hasImportSpecifierOfIdentifierModule(t: typeof babel.types, importSpecifiers: babel.types.ImportDeclaration["specifiers"]): boolean {
|
|
43
76
|
const specifier = importSpecifiers.find(specifier => {
|
|
44
77
|
// Check if it is one of:
|
|
45
78
|
// -> `import { <IMPORT_SPECIFIER_NODE> } from "core-fe";`
|
|
@@ -48,6 +81,7 @@ function hasImportSpecifierOfIdentifierModule(t, importSpecifiers) {
|
|
|
48
81
|
const importedSpecifier = specifier.imported;
|
|
49
82
|
return t.isIdentifier(importedSpecifier) && importedSpecifier.name === "Module";
|
|
50
83
|
}
|
|
84
|
+
|
|
51
85
|
// Check if it is:
|
|
52
86
|
// -> `import * as <IMPORT_NAMESPACE_SPECIFIER_NODE> from "core-fe";`
|
|
53
87
|
if (t.isImportNamespaceSpecifier(specifier)) {
|
|
@@ -55,8 +89,8 @@ function hasImportSpecifierOfIdentifierModule(t, importSpecifiers) {
|
|
|
55
89
|
// Maybe enforce "core-fe" should not be imported with a namespace with an ESLint rule?
|
|
56
90
|
return true;
|
|
57
91
|
}
|
|
92
|
+
|
|
58
93
|
return false;
|
|
59
94
|
});
|
|
60
95
|
return specifier !== undefined;
|
|
61
96
|
}
|
|
62
|
-
//# sourceMappingURL=core-fe-hmr-babel-plugin.js.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const RegExpUtil_1 = require("./RegExpUtil");
|
|
1
|
+
import type webpack from "webpack";
|
|
2
|
+
import {RegExpUtil} from "./RegExpUtil";
|
|
3
|
+
|
|
5
4
|
/**
|
|
6
5
|
* Handles dependency requests to image assets (".png", ".jpeg", ".jpg", ".gif", ".svg")
|
|
7
6
|
* by inlining as images as DataURL,
|
|
@@ -9,9 +8,9 @@ const RegExpUtil_1 = require("./RegExpUtil");
|
|
|
9
8
|
*
|
|
10
9
|
* @see https://webpack.js.org/guides/asset-modules/
|
|
11
10
|
*/
|
|
12
|
-
function imageRule() {
|
|
11
|
+
export function imageRule(): webpack.RuleSetRule {
|
|
13
12
|
return {
|
|
14
|
-
test:
|
|
13
|
+
test: RegExpUtil.fileExtension(".png", ".jpeg", ".jpg", ".gif", ".svg"),
|
|
15
14
|
type: "asset",
|
|
16
15
|
generator: {
|
|
17
16
|
filename: "static/img/[name].[hash:8][ext][query]",
|
|
@@ -23,5 +22,3 @@ function imageRule() {
|
|
|
23
22
|
},
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
|
-
exports.imageRule = imageRule;
|
|
27
|
-
//# sourceMappingURL=image.rule.js.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {imageRule} from "./image.rule";
|
|
2
|
+
import {otherRule} from "./other.rule";
|
|
3
|
+
import {stylesheetRule} from "./stylesheet.rule";
|
|
4
|
+
import {tsRule} from "./ts.rule";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Static factories to create `webpack.config#modules.rules` items.
|
|
8
|
+
*/
|
|
9
|
+
export class Rule {
|
|
10
|
+
static readonly image = imageRule;
|
|
11
|
+
|
|
12
|
+
static readonly other = otherRule;
|
|
13
|
+
|
|
14
|
+
static readonly ts = tsRule;
|
|
15
|
+
|
|
16
|
+
static readonly stylesheet = stylesheetRule;
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type webpack from "webpack";
|
|
2
|
+
import {Constant} from "../../Constant";
|
|
3
|
+
import {RegExpUtil} from "./RegExpUtil";
|
|
4
|
+
|
|
5
|
+
interface OtherRuleDeps {
|
|
6
|
+
extraExtensionsForOtherRule: string[];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Handles dependency requests to file assets
|
|
11
|
+
* by emitting as separate files.
|
|
12
|
+
*
|
|
13
|
+
* @see https://webpack.js.org/guides/asset-modules/
|
|
14
|
+
*/
|
|
15
|
+
export function otherRule({extraExtensionsForOtherRule}: OtherRuleDeps): webpack.RuleSetRule {
|
|
16
|
+
return {
|
|
17
|
+
test: RegExpUtil.fileExtension(".ico", ...Constant.mediaExtensions, ...Constant.fontExtensions, ...extraExtensionsForOtherRule),
|
|
18
|
+
type: "asset",
|
|
19
|
+
generator: {
|
|
20
|
+
filename: "static/other/[name].[hash:8][ext][query]",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function cssLoader(importLoaders) {
|
|
1
|
+
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
2
|
+
import type webpack from "webpack";
|
|
3
|
+
import {RegExpUtil} from "./RegExpUtil";
|
|
4
|
+
|
|
5
|
+
interface StylesheetRuleDeps {
|
|
6
|
+
minimize: boolean;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function cssLoader(importLoaders: number): webpack.RuleSetUseItem {
|
|
10
10
|
return {
|
|
11
11
|
loader: require.resolve("css-loader"),
|
|
12
12
|
options: {
|
|
@@ -14,7 +14,8 @@ function cssLoader(importLoaders) {
|
|
|
14
14
|
},
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
|
|
18
|
+
function lessLoader(): webpack.RuleSetUseItem {
|
|
18
19
|
return {
|
|
19
20
|
loader: require.resolve("less-loader"),
|
|
20
21
|
options: {
|
|
@@ -24,12 +25,14 @@ function lessLoader() {
|
|
|
24
25
|
},
|
|
25
26
|
};
|
|
26
27
|
}
|
|
27
|
-
|
|
28
|
+
|
|
29
|
+
function miniCssExtractPluginLoader(): webpack.RuleSetUseItem {
|
|
28
30
|
return {
|
|
29
|
-
loader: require.resolve(
|
|
31
|
+
loader: require.resolve(MiniCssExtractPlugin.loader),
|
|
30
32
|
};
|
|
31
33
|
}
|
|
32
|
-
|
|
34
|
+
|
|
35
|
+
function postcssLoader(): webpack.RuleSetUseItem {
|
|
33
36
|
return {
|
|
34
37
|
loader: require.resolve("postcss-loader"),
|
|
35
38
|
options: {
|
|
@@ -42,11 +45,13 @@ function postcssLoader() {
|
|
|
42
45
|
},
|
|
43
46
|
};
|
|
44
47
|
}
|
|
45
|
-
|
|
48
|
+
|
|
49
|
+
function styleLoader(): webpack.RuleSetUseItem {
|
|
46
50
|
return {
|
|
47
51
|
loader: require.resolve("style-loader"),
|
|
48
52
|
};
|
|
49
53
|
}
|
|
54
|
+
|
|
50
55
|
/**
|
|
51
56
|
* Handles dependency requests to stylesheet assets (".css", ".less")
|
|
52
57
|
* with `minimize: true` by `lessc` -> transform to js module -> inject to DOM as <style> tag,
|
|
@@ -58,23 +63,24 @@ function styleLoader() {
|
|
|
58
63
|
* @see https://webpack.js.org/loaders/postcss-loader/
|
|
59
64
|
* @see https://webpack.js.org/loaders/style-loader/
|
|
60
65
|
*/
|
|
61
|
-
function stylesheetRule({
|
|
62
|
-
const use = minimize
|
|
66
|
+
export function stylesheetRule({minimize}: StylesheetRuleDeps): webpack.RuleSetRule {
|
|
67
|
+
const use: webpack.RuleSetUseItem[] = minimize
|
|
63
68
|
? [
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
miniCssExtractPluginLoader(),
|
|
70
|
+
cssLoader(2),
|
|
71
|
+
postcssLoader(),
|
|
72
|
+
lessLoader(),
|
|
73
|
+
// prettier-format-preserve
|
|
74
|
+
]
|
|
70
75
|
: [
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
styleLoader(),
|
|
77
|
+
cssLoader(1),
|
|
78
|
+
lessLoader(),
|
|
79
|
+
// prettier-format-preserve
|
|
80
|
+
];
|
|
81
|
+
|
|
76
82
|
return {
|
|
77
|
-
test:
|
|
83
|
+
test: RegExpUtil.fileExtension(".css", ".less"),
|
|
78
84
|
use,
|
|
79
85
|
// Declare all css/less imports as side effects (not to be considered
|
|
80
86
|
// as dead code), regardless of the containing package claims to be
|
|
@@ -84,5 +90,3 @@ function stylesheetRule({ minimize }) {
|
|
|
84
90
|
sideEffects: true,
|
|
85
91
|
};
|
|
86
92
|
}
|
|
87
|
-
exports.stylesheetRule = stylesheetRule;
|
|
88
|
-
//# sourceMappingURL=stylesheet.rule.js.map
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import path from "path";
|
|
2
|
+
import type webpack from "webpack";
|
|
3
|
+
import {RegExpUtil} from "./RegExpUtil";
|
|
4
|
+
|
|
5
|
+
interface Deps {
|
|
6
|
+
tsconfigFilepath: string;
|
|
7
|
+
fastRefresh: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
9
10
|
/**
|
|
10
11
|
* Handles dependency requests to typescript files
|
|
11
12
|
* by compiling with `tsc`.
|
|
@@ -17,15 +18,16 @@ const RegExpUtil_1 = require("./RegExpUtil");
|
|
|
17
18
|
* @see https://github.com/TypeStrong/ts-loader
|
|
18
19
|
* @see https://github.com/pmmmwh/react-refresh-webpack-plugin
|
|
19
20
|
*/
|
|
20
|
-
function tsRule({
|
|
21
|
-
const babelLoader = {
|
|
21
|
+
export function tsRule({tsconfigFilepath, fastRefresh}: Deps): webpack.RuleSetRule {
|
|
22
|
+
const babelLoader: webpack.RuleSetUseItem = {
|
|
22
23
|
loader: require.resolve("babel-loader"),
|
|
23
24
|
options: {
|
|
24
|
-
plugins: [require.resolve(
|
|
25
|
+
plugins: [require.resolve(path.join(__dirname, "./core-fe-hmr-babel-plugin")), require.resolve("react-refresh/babel")],
|
|
25
26
|
},
|
|
26
27
|
};
|
|
28
|
+
|
|
27
29
|
// TODO/Alvis: Check whether ts-loader can be replaced by babel loader
|
|
28
|
-
const tsLoader = {
|
|
30
|
+
const tsLoader: webpack.RuleSetUseItem = {
|
|
29
31
|
loader: require.resolve("ts-loader"),
|
|
30
32
|
options: {
|
|
31
33
|
colors: false,
|
|
@@ -35,10 +37,11 @@ function tsRule({ tsconfigFilepath, fastRefresh }) {
|
|
|
35
37
|
target: "ES5",
|
|
36
38
|
noEmit: false,
|
|
37
39
|
},
|
|
38
|
-
transpileOnly:
|
|
40
|
+
transpileOnly: true,
|
|
39
41
|
},
|
|
40
42
|
};
|
|
41
|
-
|
|
43
|
+
|
|
44
|
+
const swcLoader: webpack.RuleSetUseItem = {
|
|
42
45
|
loader: require.resolve("swc-loader"),
|
|
43
46
|
options: {
|
|
44
47
|
jsc: {
|
|
@@ -57,10 +60,9 @@ function tsRule({ tsconfigFilepath, fastRefresh }) {
|
|
|
57
60
|
},
|
|
58
61
|
},
|
|
59
62
|
};
|
|
63
|
+
|
|
60
64
|
return {
|
|
61
|
-
test:
|
|
65
|
+
test: RegExpUtil.fileExtension(".ts", ".tsx"),
|
|
62
66
|
use: fastRefresh ? [babelLoader, tsLoader] : [swcLoader],
|
|
63
67
|
};
|
|
64
68
|
}
|
|
65
|
-
exports.tsRule = tsRule;
|
|
66
|
-
//# sourceMappingURL=ts.rule.js.map
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import prettyFormat from "pretty-format";
|
|
2
|
+
import type webpack from "webpack";
|
|
3
|
+
|
|
4
|
+
interface SerializableWebpackPluginDescriptor {
|
|
5
|
+
"@@WP_CONFIG_GEN_TYPE": "WebpackPluginConstructorCall";
|
|
6
|
+
pluginName: string;
|
|
7
|
+
pluginOptions: any;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class WebpackConfigSerializationUtil {
|
|
11
|
+
static serializablePlugin<OptType, T extends {apply(..._: any[]): void}>(name: string, PluginConstructor: new () => T): webpack.WebpackPluginInstance;
|
|
12
|
+
static serializablePlugin<OptType, T extends {apply(..._: any[]): void}>(name: string, PluginConstructor: new (_: OptType) => T, options: OptType): webpack.WebpackPluginInstance;
|
|
13
|
+
static serializablePlugin<OptType, T extends {apply(..._: any[]): void}>(name: string, PluginConstructor: new (_?: OptType) => T, options?: OptType): webpack.WebpackPluginInstance {
|
|
10
14
|
const plugin = new PluginConstructor(options);
|
|
11
15
|
return Object.defineProperty(plugin, "toWebpackConfigSerializableType", {
|
|
12
|
-
value() {
|
|
16
|
+
value(): SerializableWebpackPluginDescriptor {
|
|
13
17
|
return {
|
|
14
18
|
"@@WP_CONFIG_GEN_TYPE": "WebpackPluginConstructorCall",
|
|
15
19
|
pluginName: name,
|
|
@@ -18,8 +22,9 @@ class WebpackConfigSerializationUtil {
|
|
|
18
22
|
},
|
|
19
23
|
});
|
|
20
24
|
}
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
|
|
26
|
+
static configToString(config: webpack.Configuration): string {
|
|
27
|
+
const configString = prettyFormat(config, {
|
|
23
28
|
callToJSON: true,
|
|
24
29
|
escapeRegex: false,
|
|
25
30
|
escapeString: false,
|
|
@@ -27,23 +32,22 @@ class WebpackConfigSerializationUtil {
|
|
|
27
32
|
printFunctionName: false,
|
|
28
33
|
plugins: [
|
|
29
34
|
{
|
|
30
|
-
test(val) {
|
|
35
|
+
test(val: any) {
|
|
31
36
|
try {
|
|
32
37
|
return typeof val.toWebpackConfigSerializableType === "function";
|
|
33
|
-
}
|
|
34
|
-
catch (_a) {
|
|
38
|
+
} catch {
|
|
35
39
|
return false;
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
|
-
serialize(val, config, indentation, depth, refs, printer) {
|
|
39
|
-
const _ = val.toWebpackConfigSerializableType();
|
|
42
|
+
serialize(val: any, config, indentation, depth, refs, printer) {
|
|
43
|
+
const _ = val.toWebpackConfigSerializableType() as SerializableWebpackPluginDescriptor;
|
|
40
44
|
return `new ${_.pluginName}(${printer(_.pluginOptions, config, indentation, depth, refs)})`;
|
|
41
45
|
},
|
|
42
46
|
},
|
|
43
47
|
],
|
|
44
48
|
});
|
|
45
49
|
try {
|
|
46
|
-
const {
|
|
50
|
+
const {format} = require("prettier") as typeof import("prettier");
|
|
47
51
|
return format("module.exports = " + configString, {
|
|
48
52
|
arrowParens: "avoid",
|
|
49
53
|
bracketSpacing: false,
|
|
@@ -52,12 +56,9 @@ class WebpackConfigSerializationUtil {
|
|
|
52
56
|
useTabs: false,
|
|
53
57
|
filepath: "webpack.config.js",
|
|
54
58
|
});
|
|
55
|
-
}
|
|
56
|
-
catch (_a) {
|
|
59
|
+
} catch {
|
|
57
60
|
// Either prettier cannot be loaded, or formatting failed, return the unformatted config as a fallback.
|
|
58
61
|
return configString;
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
64
|
}
|
|
62
|
-
exports.WebpackConfigSerializationUtil = WebpackConfigSerializationUtil;
|
|
63
|
-
//# sourceMappingURL=WebpackConfigSerializationUtil.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type webpack from "webpack";
|
|
2
|
+
import type {EntryDescriptor} from "../type";
|
|
3
|
+
|
|
4
|
+
interface StrictWebpackEntry {
|
|
5
|
+
[entryName: string]: [string];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface WebpackEntryFactoryOptions {
|
|
9
|
+
configEntryDescriptors: EntryDescriptor[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class WebpackEntryFactory {
|
|
13
|
+
static generate({configEntryDescriptors}: WebpackEntryFactoryOptions): NonNullable<webpack.Configuration["entry"]> {
|
|
14
|
+
const entry: StrictWebpackEntry = {};
|
|
15
|
+
|
|
16
|
+
for (const {name, entryPath} of configEntryDescriptors) {
|
|
17
|
+
entry[name] = [entryPath];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return entry;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export interface WebpackOutputPublicURLFactoryOptions {
|
|
2
|
+
env: string | null;
|
|
3
|
+
/**
|
|
4
|
+
* Function to dynamically compute additional webpack config from `env`.
|
|
5
|
+
* Should validates if the config contains `publicUrl` field.
|
|
6
|
+
*/
|
|
7
|
+
webpackPublicPath: string | ((env: string) => string) | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export class WebpackOutputPublicURLFactory {
|
|
11
|
+
static generate({env, webpackPublicPath}: WebpackOutputPublicURLFactoryOptions): string {
|
|
12
|
+
if (!env || !webpackPublicPath) {
|
|
13
|
+
return "/";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (typeof webpackPublicPath === "string") {
|
|
17
|
+
return webpackPublicPath;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return webpackPublicPath(env);
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/WebpackConfigGenerator/{WebpackResolveAliasFactory.js → WebpackResolveAliasFactory.ts}
RENAMED
|
@@ -1,19 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import type {DynamicPathResolver} from "../type";
|
|
2
|
+
|
|
3
|
+
interface WebpackResolveAliasMapOptions {
|
|
4
|
+
env: string | null;
|
|
5
|
+
resolvers: DynamicPathResolver[];
|
|
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) {
|
|
8
13
|
if (prefix in moduleAliasMap) {
|
|
9
14
|
throw new Error(`Duplicated resolver prefix: ${prefix}`);
|
|
10
|
-
}
|
|
11
|
-
else if (prefix.trim() === "") {
|
|
15
|
+
} else if (prefix.trim() === "") {
|
|
12
16
|
throw new Error(`Resolver prefix cannot be empty`);
|
|
13
|
-
}
|
|
14
|
-
else if (/\s/.test(prefix)) {
|
|
17
|
+
} else if (/\s/.test(prefix)) {
|
|
15
18
|
throw new Error(`Resolver prefix cannot contain whitespace, received: ${prefix}`);
|
|
16
19
|
}
|
|
20
|
+
|
|
17
21
|
if (resolver) {
|
|
18
22
|
const resolvedRealPath = typeof resolver === "string" ? resolver : resolver(env);
|
|
19
23
|
if (resolvedRealPath) {
|
|
@@ -21,8 +25,7 @@ class WebpackResolveAliasFactory {
|
|
|
21
25
|
}
|
|
22
26
|
}
|
|
23
27
|
}
|
|
28
|
+
|
|
24
29
|
return moduleAliasMap;
|
|
25
30
|
}
|
|
26
31
|
}
|
|
27
|
-
exports.WebpackResolveAliasFactory = WebpackResolveAliasFactory;
|
|
28
|
-
//# sourceMappingURL=WebpackResolveAliasFactory.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {Constant} from "../Constant";
|
|
2
|
+
|
|
3
|
+
interface WebpackResolveExtensionsFactoryOptions {
|
|
4
|
+
prioritizedExtensionPrefixes?: string[] | undefined;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export class WebpackResolveExtensionsFactory {
|
|
8
|
+
static generate({prioritizedExtensionPrefixes = []}: WebpackResolveExtensionsFactoryOptions): string[] {
|
|
9
|
+
const resolveExtensions = [];
|
|
10
|
+
|
|
11
|
+
for (const prefix of prioritizedExtensionPrefixes) {
|
|
12
|
+
resolveExtensions.push(...Constant.resolveExtensions.map(_ => `.${prefix}${_}`));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
resolveExtensions.push(...Constant.resolveExtensions);
|
|
16
|
+
|
|
17
|
+
return resolveExtensions;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
interface WebpackResolveModulesFactoryOptions {
|
|
2
|
+
projectSrcDirectory: string;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export class WebpackResolveModulesFactory {
|
|
6
|
+
static generate({projectSrcDirectory}: WebpackResolveModulesFactoryOptions): string[] {
|
|
6
7
|
const resolveModules = [];
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* To let webpack know how to resolve non-relative paths when `tsconfig.json#compilerOptions.baseUrl` is set to "./src"
|
|
9
11
|
* Maybe refactor to a better resolution/aliasing solution later(?)
|
|
@@ -24,13 +26,13 @@ class WebpackResolveModulesFactory {
|
|
|
24
26
|
* ```
|
|
25
27
|
*/
|
|
26
28
|
resolveModules.push(projectSrcDirectory);
|
|
29
|
+
|
|
27
30
|
/**
|
|
28
31
|
* The default behavior to resolve non-relative paths is by looking inside `node_modules` folder.
|
|
29
32
|
* Put at the end so this has the lowest precedence.
|
|
30
33
|
*/
|
|
31
34
|
resolveModules.push("node_modules");
|
|
35
|
+
|
|
32
36
|
return resolveModules;
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
|
-
exports.WebpackResolveModulesFactory = WebpackResolveModulesFactory;
|
|
36
|
-
//# sourceMappingURL=WebpackResolveModulesFactory.js.map
|