@workleap/webpack-configs 1.5.2 → 1.5.4
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/CHANGELOG.md +35 -23
- package/README.md +2 -2
- package/dist/build.d.ts +18 -19
- package/dist/build.js +219 -3
- package/dist/build.js.map +1 -0
- package/dist/dev.d.ts +16 -17
- package/dist/dev.js +208 -3
- package/dist/dev.js.map +1 -0
- package/dist/index.d.ts +6 -12
- package/dist/index.js +15 -7
- package/dist/index.js.map +1 -0
- package/dist/transformers/applyTransformers.d.ts +4 -7
- package/dist/transformers/applyTransformers.js +20 -1
- package/dist/transformers/applyTransformers.js.map +1 -0
- package/dist/transformers/moduleRules.d.ts +15 -17
- package/dist/transformers/moduleRules.js +166 -1
- package/dist/transformers/moduleRules.js.map +1 -0
- package/dist/transformers/plugins.d.ts +11 -14
- package/dist/transformers/plugins.js +69 -1
- package/dist/transformers/plugins.js.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.js +6 -1
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +4 -6
- package/dist/utils.js +22 -1
- package/dist/utils.js.map +1 -0
- package/package.json +21 -24
- package/src/build.ts +240 -0
- package/src/dev.ts +233 -0
- package/src/index.ts +7 -0
- package/src/transformers/applyTransformers.ts +28 -0
- package/src/transformers/moduleRules.ts +229 -0
- package/src/transformers/plugins.ts +102 -0
- package/src/types.ts +1 -0
- package/src/utils.ts +19 -0
- package/dist/chunk-2YARCRX5.js +0 -15
- package/dist/chunk-34O5ZLZ6.js +0 -154
- package/dist/chunk-5ACA7GOB.js +0 -17
- package/dist/chunk-6F4PWJZI.js +0 -1
- package/dist/chunk-CW54GSNS.js +0 -197
- package/dist/chunk-JPURRV2F.js +0 -71
- package/dist/chunk-JU2EHEXW.js +0 -186
package/dist/chunk-34O5ZLZ6.js
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
|
|
3
|
-
// src/transformers/moduleRules.ts
|
|
4
|
-
function isNameMatchingLoader(loader, name) {
|
|
5
|
-
return loader === name || loader.indexOf(`${path.sep}${name}${path.sep}`) !== -1 || loader.indexOf(`@${name}${path.sep}`) !== -1;
|
|
6
|
-
}
|
|
7
|
-
function matchLoaderName(name) {
|
|
8
|
-
const matcher = (moduleRule) => {
|
|
9
|
-
if (typeof moduleRule === "string") {
|
|
10
|
-
return isNameMatchingLoader(moduleRule, name);
|
|
11
|
-
} else {
|
|
12
|
-
if ("loader" in moduleRule && moduleRule.loader) {
|
|
13
|
-
return isNameMatchingLoader(moduleRule.loader, name);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
return false;
|
|
17
|
-
};
|
|
18
|
-
matcher.info = {
|
|
19
|
-
type: matchLoaderName.name,
|
|
20
|
-
value: name
|
|
21
|
-
};
|
|
22
|
-
return matcher;
|
|
23
|
-
}
|
|
24
|
-
function matchAssetModuleType(type) {
|
|
25
|
-
const matcher = (moduleRule) => {
|
|
26
|
-
if (typeof moduleRule !== "string" && "type" in moduleRule) {
|
|
27
|
-
return moduleRule.type === type;
|
|
28
|
-
}
|
|
29
|
-
return false;
|
|
30
|
-
};
|
|
31
|
-
matcher.info = {
|
|
32
|
-
type: matchAssetModuleType.name,
|
|
33
|
-
value: type
|
|
34
|
-
};
|
|
35
|
-
return matcher;
|
|
36
|
-
}
|
|
37
|
-
function matchTest(test) {
|
|
38
|
-
const matcher = (moduleRule) => {
|
|
39
|
-
if (typeof moduleRule !== "string" && "test" in moduleRule) {
|
|
40
|
-
if (typeof moduleRule.test === "object" && typeof test === "object") {
|
|
41
|
-
return moduleRule.test.toString() === test.toString();
|
|
42
|
-
}
|
|
43
|
-
return moduleRule.test === test;
|
|
44
|
-
}
|
|
45
|
-
return false;
|
|
46
|
-
};
|
|
47
|
-
matcher.info = {
|
|
48
|
-
type: matchTest.name,
|
|
49
|
-
value: test.toString()
|
|
50
|
-
};
|
|
51
|
-
return matcher;
|
|
52
|
-
}
|
|
53
|
-
function toMatch(moduleRule, index, parent) {
|
|
54
|
-
return {
|
|
55
|
-
moduleRule,
|
|
56
|
-
index,
|
|
57
|
-
parent
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
function isRuleSetRule(value) {
|
|
61
|
-
return value.use !== void 0 || value.oneOf !== void 0;
|
|
62
|
-
}
|
|
63
|
-
function findModuleRulesRecursively(moduleRules, matcher, parent, matches) {
|
|
64
|
-
moduleRules.forEach((x, index, array) => {
|
|
65
|
-
if (x) {
|
|
66
|
-
if (matcher(x, index, array)) {
|
|
67
|
-
matches.push(toMatch(x, index, parent));
|
|
68
|
-
} else {
|
|
69
|
-
if (isRuleSetRule(x)) {
|
|
70
|
-
if (x.use) {
|
|
71
|
-
findModuleRulesRecursively(x.use, matcher, x.use, matches);
|
|
72
|
-
} else if (x.oneOf) {
|
|
73
|
-
findModuleRulesRecursively(x.oneOf, matcher, x.oneOf, matches);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
function findModuleRule(config, matcher) {
|
|
81
|
-
const moduleRules = config.module?.rules;
|
|
82
|
-
if (!moduleRules) {
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
const matches = [];
|
|
86
|
-
findModuleRulesRecursively(moduleRules, matcher, moduleRules, matches);
|
|
87
|
-
if (matches.length > 1) {
|
|
88
|
-
const matcherInfo = matcher.info;
|
|
89
|
-
throw new Error(`[webpack-configs] Found more than 1 matching module rule.
|
|
90
|
-
[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"
|
|
91
|
-
[webpack-configs] Matches: "${JSON.stringify(matches.map((x) => x.moduleRule))}"`);
|
|
92
|
-
}
|
|
93
|
-
return matches[0];
|
|
94
|
-
}
|
|
95
|
-
function findModuleRules(config, matcher) {
|
|
96
|
-
const moduleRules = config.module?.rules;
|
|
97
|
-
if (!moduleRules) {
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
const matches = [];
|
|
101
|
-
findModuleRulesRecursively(moduleRules, matcher, moduleRules, matches);
|
|
102
|
-
return matches;
|
|
103
|
-
}
|
|
104
|
-
function addBeforeModuleRule(config, matcher, newModuleRules) {
|
|
105
|
-
const match = findModuleRule(config, matcher);
|
|
106
|
-
if (match) {
|
|
107
|
-
match.parent.splice(match.index, 0, ...newModuleRules);
|
|
108
|
-
} else {
|
|
109
|
-
const matcherInfo = matcher.info;
|
|
110
|
-
throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.
|
|
111
|
-
[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function addAfterModuleRule(config, matcher, newModuleRules) {
|
|
115
|
-
const match = findModuleRule(config, matcher);
|
|
116
|
-
if (match) {
|
|
117
|
-
match.parent.splice(match.index + 1, 0, ...newModuleRules);
|
|
118
|
-
} else {
|
|
119
|
-
const matcherInfo = matcher.info;
|
|
120
|
-
throw new Error(`[webpack-configs] Couldn't add the new module rules because no match has been found.
|
|
121
|
-
[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function replaceModuleRule(config, matcher, newModuleRule) {
|
|
125
|
-
const match = findModuleRule(config, matcher);
|
|
126
|
-
if (match) {
|
|
127
|
-
match.parent[match.index] = newModuleRule;
|
|
128
|
-
} else {
|
|
129
|
-
const matcherInfo = matcher.info;
|
|
130
|
-
throw new Error(`[webpack-configs] Couldn't replace the module rule because no match has been found.
|
|
131
|
-
[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
function removeModuleRules(config, matcher) {
|
|
135
|
-
const moduleRules = config.module?.rules;
|
|
136
|
-
if (!moduleRules) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const matches = [];
|
|
140
|
-
findModuleRulesRecursively(moduleRules, matcher, moduleRules, matches);
|
|
141
|
-
if (matches.length > 0) {
|
|
142
|
-
const initialParentLengths = new Map(matches.map((x) => [x.parent, x.parent.length]));
|
|
143
|
-
matches.forEach((x) => {
|
|
144
|
-
const positionAdjustment = initialParentLengths.get(x.parent) - x.parent.length;
|
|
145
|
-
x.parent.splice(x.index - positionAdjustment, 1);
|
|
146
|
-
});
|
|
147
|
-
} else {
|
|
148
|
-
const matcherInfo = matcher.info;
|
|
149
|
-
throw new Error(`[webpack-configs] Didn't remove any module rules because no match has been found.
|
|
150
|
-
[webpack-configs] Matcher: "${matcherInfo}"`);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export { addAfterModuleRule, addBeforeModuleRule, findModuleRule, findModuleRules, matchAssetModuleType, matchLoaderName, matchTest, removeModuleRules, replaceModuleRule };
|
package/dist/chunk-5ACA7GOB.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// src/transformers/applyTransformers.ts
|
|
2
|
-
function applyTransformers(config, transformers, context) {
|
|
3
|
-
let count = 0;
|
|
4
|
-
const transformedConfig = transformers.reduce((acc, transformer) => {
|
|
5
|
-
const newConfig = transformer(acc, context);
|
|
6
|
-
count += 1;
|
|
7
|
-
return newConfig;
|
|
8
|
-
}, config);
|
|
9
|
-
if (context.verbose) {
|
|
10
|
-
if (count > 0) {
|
|
11
|
-
console.log(`[webpack-configs] Applied ${count} configuration transformers.`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return transformedConfig;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export { applyTransformers };
|
package/dist/chunk-6F4PWJZI.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
|
package/dist/chunk-CW54GSNS.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { isObject } from './chunk-2YARCRX5.js';
|
|
2
|
-
import { applyTransformers } from './chunk-5ACA7GOB.js';
|
|
3
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
4
|
-
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
5
|
-
import { createRequire } from 'node:module';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
import TerserPlugin from 'terser-webpack-plugin';
|
|
8
|
-
import webpack from 'webpack';
|
|
9
|
-
|
|
10
|
-
var DefinePlugin = webpack.DefinePlugin;
|
|
11
|
-
var require2 = createRequire(import.meta.url);
|
|
12
|
-
function defineBuildHtmlWebpackPluginConfig(options = {}) {
|
|
13
|
-
const {
|
|
14
|
-
template = path.resolve("./public/index.html"),
|
|
15
|
-
...rest
|
|
16
|
-
} = options;
|
|
17
|
-
return {
|
|
18
|
-
...rest,
|
|
19
|
-
template
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function defineMiniCssExtractPluginConfig(options = {}) {
|
|
23
|
-
const {
|
|
24
|
-
filename = "[name].css",
|
|
25
|
-
...rest
|
|
26
|
-
} = options;
|
|
27
|
-
return {
|
|
28
|
-
...rest,
|
|
29
|
-
filename
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
function getOptimizationConfig(optimize) {
|
|
33
|
-
if (optimize === "readable") {
|
|
34
|
-
return {
|
|
35
|
-
minimize: true,
|
|
36
|
-
minimizer: [
|
|
37
|
-
new TerserPlugin({
|
|
38
|
-
minify: TerserPlugin.swcMinify,
|
|
39
|
-
terserOptions: {
|
|
40
|
-
toplevel: true,
|
|
41
|
-
mangle: false,
|
|
42
|
-
keep_classnames: true,
|
|
43
|
-
keep_fnames: true,
|
|
44
|
-
compress: {
|
|
45
|
-
toplevel: true,
|
|
46
|
-
hoist_props: false
|
|
47
|
-
},
|
|
48
|
-
output: {
|
|
49
|
-
comments: true
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
})
|
|
53
|
-
],
|
|
54
|
-
chunkIds: "named",
|
|
55
|
-
moduleIds: "named",
|
|
56
|
-
mangleExports: false,
|
|
57
|
-
mangleWasmImports: false
|
|
58
|
-
};
|
|
59
|
-
} else if (optimize) {
|
|
60
|
-
return {
|
|
61
|
-
minimize: true,
|
|
62
|
-
minimizer: [
|
|
63
|
-
new TerserPlugin({
|
|
64
|
-
minify: TerserPlugin.swcMinify
|
|
65
|
-
})
|
|
66
|
-
]
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
return {
|
|
70
|
-
minimize: false,
|
|
71
|
-
chunkIds: "named",
|
|
72
|
-
moduleIds: "named",
|
|
73
|
-
concatenateModules: false,
|
|
74
|
-
flagIncludedChunks: false,
|
|
75
|
-
mangleExports: false,
|
|
76
|
-
mangleWasmImports: false,
|
|
77
|
-
removeAvailableModules: false,
|
|
78
|
-
usedExports: false
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
function defineBuildConfig(swcConfig, options = {}) {
|
|
82
|
-
const {
|
|
83
|
-
entry = path.resolve("./src/index.tsx"),
|
|
84
|
-
outputPath = path.resolve("dist"),
|
|
85
|
-
// The trailing / is very important, otherwise paths will not be resolved correctly.
|
|
86
|
-
publicPath = "http://localhost:8080/",
|
|
87
|
-
moduleRules = [],
|
|
88
|
-
plugins = [],
|
|
89
|
-
htmlWebpackPlugin = defineBuildHtmlWebpackPluginConfig(),
|
|
90
|
-
miniCssExtractPluginOptions = defineMiniCssExtractPluginConfig(),
|
|
91
|
-
optimize = true,
|
|
92
|
-
cssModules = false,
|
|
93
|
-
svgr = true,
|
|
94
|
-
// Using an empty object literal as the default value to ensure
|
|
95
|
-
// "process.env" is always available.
|
|
96
|
-
environmentVariables = {},
|
|
97
|
-
transformers = [],
|
|
98
|
-
verbose = false
|
|
99
|
-
} = options;
|
|
100
|
-
const config = {
|
|
101
|
-
mode: "production",
|
|
102
|
-
target: "web",
|
|
103
|
-
entry,
|
|
104
|
-
output: {
|
|
105
|
-
path: outputPath,
|
|
106
|
-
filename: "[name].js",
|
|
107
|
-
publicPath,
|
|
108
|
-
clean: true,
|
|
109
|
-
assetModuleFilename: "[name][ext][query]"
|
|
110
|
-
},
|
|
111
|
-
optimization: getOptimizationConfig(optimize),
|
|
112
|
-
infrastructureLogging: verbose ? {
|
|
113
|
-
appendOnly: true,
|
|
114
|
-
level: "verbose",
|
|
115
|
-
debug: /PackFileCache/
|
|
116
|
-
} : void 0,
|
|
117
|
-
module: {
|
|
118
|
-
rules: [
|
|
119
|
-
{
|
|
120
|
-
test: /\.(js|jsx|ts|tsx)$/i,
|
|
121
|
-
exclude: /node_modules/,
|
|
122
|
-
loader: require2.resolve("swc-loader"),
|
|
123
|
-
options: swcConfig
|
|
124
|
-
},
|
|
125
|
-
{
|
|
126
|
-
// https://stackoverflow.com/questions/69427025/programmatic-webpack-jest-esm-cant-resolve-module-without-js-file-exten
|
|
127
|
-
test: /\.js$/i,
|
|
128
|
-
include: /node_modules/,
|
|
129
|
-
resolve: {
|
|
130
|
-
fullySpecified: false
|
|
131
|
-
}
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
test: /\.css$/i,
|
|
135
|
-
use: [
|
|
136
|
-
{ loader: MiniCssExtractPlugin.loader },
|
|
137
|
-
{
|
|
138
|
-
loader: require2.resolve("css-loader"),
|
|
139
|
-
options: cssModules ? {
|
|
140
|
-
// Must match the number of loaders applied before this one.
|
|
141
|
-
importLoaders: 1,
|
|
142
|
-
modules: true
|
|
143
|
-
} : void 0
|
|
144
|
-
},
|
|
145
|
-
{ loader: require2.resolve("postcss-loader") }
|
|
146
|
-
]
|
|
147
|
-
},
|
|
148
|
-
...svgr ? [
|
|
149
|
-
{
|
|
150
|
-
test: /\.svg$/i,
|
|
151
|
-
loader: require2.resolve("@svgr/webpack"),
|
|
152
|
-
options: isObject(svgr) ? svgr : void 0
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
test: /\.(png|jpe?g|gif)$/i,
|
|
156
|
-
type: "asset/resource"
|
|
157
|
-
}
|
|
158
|
-
] : [
|
|
159
|
-
{
|
|
160
|
-
test: /\.(png|jpe?g|gif|svg)$/i,
|
|
161
|
-
type: "asset/resource"
|
|
162
|
-
}
|
|
163
|
-
],
|
|
164
|
-
...moduleRules
|
|
165
|
-
]
|
|
166
|
-
},
|
|
167
|
-
resolve: {
|
|
168
|
-
extensions: [".js", ".jsx", ".ts", ".tsx", ".css"],
|
|
169
|
-
alias: {
|
|
170
|
-
// Fixes Module not found: Error: Can't resolve '@swc/helpers/_/_class_private_field_init'.
|
|
171
|
-
// View https://github.com/vercel/next.js/pull/38174 for more information and https://github.com/vercel/next.js/issues/48593.
|
|
172
|
-
"@swc/helpers": path.dirname(require2.resolve("@swc/helpers/package.json"))
|
|
173
|
-
}
|
|
174
|
-
},
|
|
175
|
-
plugins: [
|
|
176
|
-
htmlWebpackPlugin && new HtmlWebpackPlugin(isObject(htmlWebpackPlugin) ? htmlWebpackPlugin : defineBuildHtmlWebpackPluginConfig()),
|
|
177
|
-
new MiniCssExtractPlugin(miniCssExtractPluginOptions),
|
|
178
|
-
// Stringify the environment variables because the plugin does a direct text replacement. Otherwise, "production" would become production
|
|
179
|
-
// after replacement and cause an undefined var error because the production var doesn't exist.
|
|
180
|
-
// For more information, view: https://webpack.js.org/plugins/define-plugin.
|
|
181
|
-
new DefinePlugin({
|
|
182
|
-
"process.env": Object.keys(environmentVariables).reduce((acc, key) => {
|
|
183
|
-
acc[key] = JSON.stringify(environmentVariables[key]);
|
|
184
|
-
return acc;
|
|
185
|
-
}, {})
|
|
186
|
-
}),
|
|
187
|
-
...plugins
|
|
188
|
-
].filter(Boolean)
|
|
189
|
-
};
|
|
190
|
-
const transformedConfig = applyTransformers(config, transformers, {
|
|
191
|
-
environment: "build",
|
|
192
|
-
verbose
|
|
193
|
-
});
|
|
194
|
-
return transformedConfig;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export { defineBuildConfig, defineBuildHtmlWebpackPluginConfig, defineMiniCssExtractPluginConfig, getOptimizationConfig };
|
package/dist/chunk-JPURRV2F.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// src/transformers/plugins.ts
|
|
2
|
-
function matchConstructorName(name) {
|
|
3
|
-
const matcher = (plugin) => {
|
|
4
|
-
return plugin?.constructor.name === name;
|
|
5
|
-
};
|
|
6
|
-
matcher.info = {
|
|
7
|
-
type: matchConstructorName.name,
|
|
8
|
-
value: name
|
|
9
|
-
};
|
|
10
|
-
return matcher;
|
|
11
|
-
}
|
|
12
|
-
function findPlugin(config, matcher) {
|
|
13
|
-
const matches = [];
|
|
14
|
-
config.plugins?.forEach((x, index, array) => {
|
|
15
|
-
if (matcher(x, index, array)) {
|
|
16
|
-
matches.push({
|
|
17
|
-
plugin: x,
|
|
18
|
-
index
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
if (matches.length > 1) {
|
|
23
|
-
const matcherInfo = matcher.info;
|
|
24
|
-
throw new Error(`[webpack-configs] Found more than 1 matching plugin.
|
|
25
|
-
[webp-configs] Matcher: "${JSON.stringify(matcherInfo)}"
|
|
26
|
-
[webpack-configs] Matches: "${JSON.stringify(matches.map((x) => x.plugin))}"`);
|
|
27
|
-
}
|
|
28
|
-
return matches[0];
|
|
29
|
-
}
|
|
30
|
-
function replacePlugin(config, matcher, newPlugin) {
|
|
31
|
-
const match = findPlugin(config, matcher);
|
|
32
|
-
if (match) {
|
|
33
|
-
config.plugins[match.index] = newPlugin;
|
|
34
|
-
} else {
|
|
35
|
-
const matcherInfo = matcher.info;
|
|
36
|
-
throw new Error(`[webpack-configs] Couldn't replace the plugin because no match has been found.
|
|
37
|
-
[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function addBeforePlugin(config, matcher, newPlugins) {
|
|
41
|
-
const match = findPlugin(config, matcher);
|
|
42
|
-
if (match) {
|
|
43
|
-
config.plugins?.splice(match.index, 0, ...newPlugins);
|
|
44
|
-
} else {
|
|
45
|
-
const matcherInfo = matcher.info;
|
|
46
|
-
throw new Error(`[webpack-configs] Couldn't add the new plugins because no match has been found.
|
|
47
|
-
[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
function addAfterPlugin(config, matcher, newPlugins) {
|
|
51
|
-
const match = findPlugin(config, matcher);
|
|
52
|
-
if (match) {
|
|
53
|
-
config.plugins?.splice(match.index + 1, 0, ...newPlugins);
|
|
54
|
-
} else {
|
|
55
|
-
const matcherInfo = matcher.info;
|
|
56
|
-
throw new Error(`[webpack-configs] Couldn't add the new plugins because no match has been found.
|
|
57
|
-
[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
function removePlugin(config, matcher) {
|
|
61
|
-
const countBefore = config.plugins?.length ?? 0;
|
|
62
|
-
config.plugins = config.plugins?.filter((...args) => !matcher(...args));
|
|
63
|
-
const countAfter = config.plugins?.length ?? 0;
|
|
64
|
-
if (countBefore === countAfter) {
|
|
65
|
-
const matcherInfo = matcher.info;
|
|
66
|
-
throw new Error(`[webpack-configs] Didn't remove any plugin because no match has been found.
|
|
67
|
-
[webpack-configs] Matcher: "${JSON.stringify(matcherInfo)}"`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export { addAfterPlugin, addBeforePlugin, findPlugin, matchConstructorName, removePlugin, replacePlugin };
|
package/dist/chunk-JU2EHEXW.js
DELETED
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { isObject, isNil } from './chunk-2YARCRX5.js';
|
|
2
|
-
import { applyTransformers } from './chunk-5ACA7GOB.js';
|
|
3
|
-
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
|
|
4
|
-
import HtmlWebpackPlugin from 'html-webpack-plugin';
|
|
5
|
-
import { createRequire } from 'node:module';
|
|
6
|
-
import path from 'node:path';
|
|
7
|
-
import webpack from 'webpack';
|
|
8
|
-
import 'webpack-dev-server';
|
|
9
|
-
|
|
10
|
-
var DefinePlugin = webpack.DefinePlugin;
|
|
11
|
-
var require2 = createRequire(import.meta.url);
|
|
12
|
-
function defineDevHtmlWebpackPluginConfig(options = {}) {
|
|
13
|
-
const {
|
|
14
|
-
template = path.resolve("./public/index.html"),
|
|
15
|
-
...rest
|
|
16
|
-
} = options;
|
|
17
|
-
return {
|
|
18
|
-
...rest,
|
|
19
|
-
template
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
function defineFastRefreshPluginConfig(options = {}) {
|
|
23
|
-
return options;
|
|
24
|
-
}
|
|
25
|
-
function preflight() {
|
|
26
|
-
if (!require2.resolve("webpack-dev-server")) {
|
|
27
|
-
throw new Error('[webpack-configs] To use the "dev" config, install https://www.npmjs.com/package/webpack-dev-server as a "devDependency".');
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
function trySetSwcFastRefresh(config, enabled) {
|
|
31
|
-
if (config?.jsc?.transform?.react) {
|
|
32
|
-
config.jsc.transform.react.refresh = enabled;
|
|
33
|
-
}
|
|
34
|
-
return config;
|
|
35
|
-
}
|
|
36
|
-
function trySetFastRefreshOverlay(options, overlay) {
|
|
37
|
-
if (overlay === false && isNil(options.overlay)) {
|
|
38
|
-
options.overlay = false;
|
|
39
|
-
}
|
|
40
|
-
return options;
|
|
41
|
-
}
|
|
42
|
-
function defineDevConfig(swcConfig, options = {}) {
|
|
43
|
-
preflight();
|
|
44
|
-
const {
|
|
45
|
-
entry = path.resolve("./src/index.tsx"),
|
|
46
|
-
https = false,
|
|
47
|
-
host = "localhost",
|
|
48
|
-
port = 8080,
|
|
49
|
-
publicPath,
|
|
50
|
-
cache = true,
|
|
51
|
-
moduleRules = [],
|
|
52
|
-
plugins = [],
|
|
53
|
-
htmlWebpackPlugin = defineDevHtmlWebpackPluginConfig(),
|
|
54
|
-
fastRefresh = true,
|
|
55
|
-
cssModules = false,
|
|
56
|
-
overlay,
|
|
57
|
-
svgr = true,
|
|
58
|
-
// Using an empty object literal as the default value to ensure
|
|
59
|
-
// "process.env" is always available.
|
|
60
|
-
environmentVariables = {},
|
|
61
|
-
transformers = [],
|
|
62
|
-
verbose = false
|
|
63
|
-
} = options;
|
|
64
|
-
const config = {
|
|
65
|
-
mode: "development",
|
|
66
|
-
target: "web",
|
|
67
|
-
devtool: "eval-cheap-module-source-map",
|
|
68
|
-
devServer: {
|
|
69
|
-
// According to the Fast Refresh plugin documentation, hot should be "true" to enable Fast Refresh:
|
|
70
|
-
// https://github.com/pmmmwh/react-refresh-webpack-plugin#usage.
|
|
71
|
-
hot: true,
|
|
72
|
-
host,
|
|
73
|
-
port,
|
|
74
|
-
historyApiFallback: true,
|
|
75
|
-
client: overlay === false || fastRefresh ? {
|
|
76
|
-
overlay: false
|
|
77
|
-
} : void 0,
|
|
78
|
-
server: https ? {
|
|
79
|
-
type: "https",
|
|
80
|
-
options: isObject(https) ? https : void 0
|
|
81
|
-
} : void 0
|
|
82
|
-
},
|
|
83
|
-
entry,
|
|
84
|
-
output: {
|
|
85
|
-
// The trailing / is very important, otherwise paths will not be resolved correctly.
|
|
86
|
-
publicPath: publicPath ?? `${https ? "https" : "http"}://${host}:${port}/`
|
|
87
|
-
},
|
|
88
|
-
cache: cache && {
|
|
89
|
-
type: "memory",
|
|
90
|
-
maxGenerations: 1
|
|
91
|
-
},
|
|
92
|
-
// See: https://webpack.js.org/guides/build-performance/#avoid-extra-optimization-steps
|
|
93
|
-
optimization: {
|
|
94
|
-
// Keep "runtimeChunk" to false, otherwise it breaks module federation
|
|
95
|
-
// (at least for the remote application).
|
|
96
|
-
runtimeChunk: false,
|
|
97
|
-
removeAvailableModules: false,
|
|
98
|
-
removeEmptyChunks: false,
|
|
99
|
-
splitChunks: false
|
|
100
|
-
},
|
|
101
|
-
infrastructureLogging: verbose ? {
|
|
102
|
-
appendOnly: true,
|
|
103
|
-
level: "verbose",
|
|
104
|
-
debug: /PackFileCache/
|
|
105
|
-
} : void 0,
|
|
106
|
-
module: {
|
|
107
|
-
rules: [
|
|
108
|
-
{
|
|
109
|
-
test: /\.(js|jsx|ts|tsx)$/i,
|
|
110
|
-
exclude: /node_modules/,
|
|
111
|
-
loader: require2.resolve("swc-loader"),
|
|
112
|
-
options: trySetSwcFastRefresh(swcConfig, fastRefresh !== false)
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
// https://stackoverflow.com/questions/69427025/programmatic-webpack-jest-esm-cant-resolve-module-without-js-file-exten
|
|
116
|
-
test: /\.js$/i,
|
|
117
|
-
include: /node_modules/,
|
|
118
|
-
resolve: {
|
|
119
|
-
fullySpecified: false
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
test: /\.css$/i,
|
|
124
|
-
use: [
|
|
125
|
-
{ loader: require2.resolve("style-loader") },
|
|
126
|
-
{
|
|
127
|
-
loader: require2.resolve("css-loader"),
|
|
128
|
-
options: cssModules ? {
|
|
129
|
-
// Must match the number of loaders applied before this one.
|
|
130
|
-
importLoaders: 1,
|
|
131
|
-
modules: true
|
|
132
|
-
} : void 0
|
|
133
|
-
},
|
|
134
|
-
{ loader: require2.resolve("postcss-loader") }
|
|
135
|
-
]
|
|
136
|
-
},
|
|
137
|
-
...svgr ? [
|
|
138
|
-
{
|
|
139
|
-
test: /\.svg$/i,
|
|
140
|
-
loader: require2.resolve("@svgr/webpack"),
|
|
141
|
-
options: isObject(svgr) ? svgr : void 0
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
test: /\.(png|jpe?g|gif)$/i,
|
|
145
|
-
type: "asset/resource"
|
|
146
|
-
}
|
|
147
|
-
] : [
|
|
148
|
-
{
|
|
149
|
-
test: /\.(png|jpe?g|gif|svg)$/i,
|
|
150
|
-
type: "asset/resource"
|
|
151
|
-
}
|
|
152
|
-
],
|
|
153
|
-
...moduleRules
|
|
154
|
-
]
|
|
155
|
-
},
|
|
156
|
-
resolve: {
|
|
157
|
-
extensions: [".js", ".jsx", ".ts", ".tsx", ".css"],
|
|
158
|
-
alias: {
|
|
159
|
-
// Fixes Module not found: Error: Can't resolve '@swc/helpers/_/_class_private_field_init'.
|
|
160
|
-
// View https://github.com/vercel/next.js/pull/38174 for more information and https://github.com/vercel/next.js/issues/48593.
|
|
161
|
-
"@swc/helpers": path.dirname(require2.resolve("@swc/helpers/package.json"))
|
|
162
|
-
}
|
|
163
|
-
},
|
|
164
|
-
plugins: [
|
|
165
|
-
htmlWebpackPlugin && new HtmlWebpackPlugin(isObject(htmlWebpackPlugin) ? htmlWebpackPlugin : defineDevHtmlWebpackPluginConfig()),
|
|
166
|
-
// Stringify the environment variables because the plugin does a direct text replacement. Otherwise, "production" would become production
|
|
167
|
-
// after replacement and cause an undefined var error.
|
|
168
|
-
// For more information, view: https://webpack.js.org/plugins/define-plugin/.
|
|
169
|
-
new DefinePlugin({
|
|
170
|
-
"process.env": Object.keys(environmentVariables).reduce((acc, key) => {
|
|
171
|
-
acc[key] = JSON.stringify(environmentVariables[key]);
|
|
172
|
-
return acc;
|
|
173
|
-
}, {})
|
|
174
|
-
}),
|
|
175
|
-
fastRefresh && new ReactRefreshWebpackPlugin(trySetFastRefreshOverlay(isObject(fastRefresh) ? fastRefresh : defineFastRefreshPluginConfig(), overlay)),
|
|
176
|
-
...plugins
|
|
177
|
-
].filter(Boolean)
|
|
178
|
-
};
|
|
179
|
-
const transformedConfig = applyTransformers(config, transformers, {
|
|
180
|
-
environment: "dev",
|
|
181
|
-
verbose
|
|
182
|
-
});
|
|
183
|
-
return transformedConfig;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export { defineDevConfig, defineDevHtmlWebpackPluginConfig, defineFastRefreshPluginConfig };
|