@qse/edu-scripts 1.14.11 → 1.14.13
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 +10 -0
- package/lib/build.js +0 -3
- package/lib/config/babel.dependencies.js +27 -3
- package/lib/config/babel.js +8 -10
- package/lib/config/webpackConfig.js +13 -25
- package/lib/utils/FileSizeReporter.js +4 -0
- package/lib/utils/getOverride.js +36 -0
- package/package.json +2 -3
- package/src/build.js +0 -3
- package/src/config/babel.dependencies.js +4 -3
- package/src/config/babel.js +8 -10
- package/src/config/webpackConfig.js +13 -26
- package/src/utils/FileSizeReporter.js +7 -0
- package/src/utils/getOverride.js +15 -0
package/CHANGELOG.md
CHANGED
package/lib/build.js
CHANGED
|
@@ -42,8 +42,6 @@ module.exports = async function build(args) {
|
|
|
42
42
|
process.exit(1);
|
|
43
43
|
}
|
|
44
44
|
console.log(stats.toString({ colors: true, preset: "errors-warnings", timings: true }));
|
|
45
|
-
console.log();
|
|
46
|
-
console.log("gzip 后文件大小:\n");
|
|
47
45
|
printFileSizesAfterBuild(
|
|
48
46
|
stats,
|
|
49
47
|
previousSizeMap,
|
|
@@ -51,7 +49,6 @@ module.exports = async function build(args) {
|
|
|
51
49
|
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
|
52
50
|
WARN_AFTER_CHUNK_GZIP_SIZE
|
|
53
51
|
);
|
|
54
|
-
console.log();
|
|
55
52
|
if (appConfig.single) {
|
|
56
53
|
console.log(`打包完成,可以使用 ${chalk.green("@qse/ssh-sftp")} 自动部署代码到 v1`);
|
|
57
54
|
} else {
|
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
|
|
1
24
|
// src/config/babel.dependencies.js
|
|
2
25
|
var getOverride = require("../utils/getOverride");
|
|
3
26
|
module.exports = function getBabelConfig(opts = {}) {
|
|
@@ -13,7 +36,7 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
13
36
|
inputSourceMap: isDev,
|
|
14
37
|
presets: [
|
|
15
38
|
[
|
|
16
|
-
"@babel/preset-env",
|
|
39
|
+
require.resolve("@babel/preset-env"),
|
|
17
40
|
{
|
|
18
41
|
modules: opts.modules,
|
|
19
42
|
useBuiltIns: "entry",
|
|
@@ -25,8 +48,9 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
25
48
|
].filter(Boolean),
|
|
26
49
|
plugins: [
|
|
27
50
|
[
|
|
28
|
-
"@babel/plugin-transform-runtime",
|
|
51
|
+
require.resolve("@babel/plugin-transform-runtime"),
|
|
29
52
|
{
|
|
53
|
+
absoluteRuntime: true,
|
|
30
54
|
corejs: false,
|
|
31
55
|
helpers: true,
|
|
32
56
|
// By default, babel assumes babel/runtime version 7.0.0-beta.0,
|
|
@@ -41,7 +65,7 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
41
65
|
}
|
|
42
66
|
],
|
|
43
67
|
[
|
|
44
|
-
"import",
|
|
68
|
+
require.resolve("babel-plugin-import"),
|
|
45
69
|
{ libraryName: "lodash", libraryDirectory: "", camel2DashComponentName: false },
|
|
46
70
|
"lodash"
|
|
47
71
|
]
|
package/lib/config/babel.js
CHANGED
|
@@ -46,7 +46,7 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
46
46
|
configFile: false,
|
|
47
47
|
presets: [
|
|
48
48
|
[
|
|
49
|
-
"@babel/preset-env",
|
|
49
|
+
require.resolve("@babel/preset-env"),
|
|
50
50
|
{
|
|
51
51
|
modules: opts.modules,
|
|
52
52
|
useBuiltIns: "entry",
|
|
@@ -56,19 +56,20 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
56
56
|
}
|
|
57
57
|
],
|
|
58
58
|
[
|
|
59
|
-
"@babel/preset-react",
|
|
59
|
+
require.resolve("@babel/preset-react"),
|
|
60
60
|
{
|
|
61
61
|
development: isDev,
|
|
62
62
|
runtime: hasJsxRuntime ? "automatic" : "classic",
|
|
63
63
|
useBuiltIns: !hasJsxRuntime
|
|
64
64
|
}
|
|
65
65
|
],
|
|
66
|
-
isTypeScriptEnabled && "@babel/preset-typescript"
|
|
66
|
+
isTypeScriptEnabled && require.resolve("@babel/preset-typescript")
|
|
67
67
|
].filter(Boolean),
|
|
68
68
|
plugins: [
|
|
69
69
|
[
|
|
70
|
-
"@babel/plugin-transform-runtime",
|
|
70
|
+
require.resolve("@babel/plugin-transform-runtime"),
|
|
71
71
|
{
|
|
72
|
+
absoluteRuntime: true,
|
|
72
73
|
corejs: false,
|
|
73
74
|
helpers: true,
|
|
74
75
|
// By default, babel assumes babel/runtime version 7.0.0-beta.0,
|
|
@@ -82,16 +83,13 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
82
83
|
// useESModules: true,
|
|
83
84
|
}
|
|
84
85
|
],
|
|
85
|
-
["@babel/plugin-proposal-decorators", {
|
|
86
|
-
["@babel/plugin-transform-class-properties", { loose: true }],
|
|
87
|
-
["@babel/plugin-transform-private-methods", { loose: true }],
|
|
88
|
-
["@babel/plugin-transform-private-property-in-object", { loose: true }],
|
|
86
|
+
[require.resolve("@babel/plugin-proposal-decorators"), { version: "2023-11" }],
|
|
89
87
|
[
|
|
90
|
-
"import",
|
|
88
|
+
require.resolve("babel-plugin-import"),
|
|
91
89
|
{ libraryName: "lodash", libraryDirectory: "", camel2DashComponentName: false },
|
|
92
90
|
"lodash"
|
|
93
91
|
],
|
|
94
|
-
isDev && "react-refresh/babel",
|
|
92
|
+
isDev && require.resolve("react-refresh/babel"),
|
|
95
93
|
addWebpackChunkName
|
|
96
94
|
].filter(Boolean)
|
|
97
95
|
};
|
|
@@ -33,7 +33,6 @@ var CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin");
|
|
|
33
33
|
var appPkg = require(paths.package);
|
|
34
34
|
var appConfig = require("../utils/appConfig");
|
|
35
35
|
var { ESBuildMinifyPlugin } = require("esbuild-loader");
|
|
36
|
-
var ImageMinimizerPlugin = require("image-minimizer-webpack-plugin");
|
|
37
36
|
var once = require("lodash/once");
|
|
38
37
|
var jsMainPath = appConfig.grayscale ? `${appPkg.name}/beta/${appPkg.name}` : `${appPkg.name}/${appPkg.name}`;
|
|
39
38
|
var assetPath = appConfig.grayscale ? `${appPkg.name}/beta/${appPkg.version}` : `${appPkg.name}/${appPkg.version}`;
|
|
@@ -63,18 +62,18 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
63
62
|
const getStyleLoaders = (cssOptions, preProcessor) => {
|
|
64
63
|
const loaders = [
|
|
65
64
|
{
|
|
66
|
-
loader: "style-loader",
|
|
65
|
+
loader: require.resolve("style-loader"),
|
|
67
66
|
options: { attributes: { "data-module": appPkg.name, "data-version": appPkg.version } }
|
|
68
67
|
},
|
|
69
68
|
{
|
|
70
|
-
loader: "css-loader",
|
|
69
|
+
loader: require.resolve("css-loader"),
|
|
71
70
|
options: cssOptions
|
|
72
71
|
},
|
|
73
72
|
{
|
|
74
73
|
// Options for PostCSS as we reference these options twice
|
|
75
74
|
// Adds vendor prefixing based on your specified browser support in
|
|
76
75
|
// package.json
|
|
77
|
-
loader: "postcss-loader",
|
|
76
|
+
loader: require.resolve("postcss-loader"),
|
|
78
77
|
options: {
|
|
79
78
|
postcssOptions: {
|
|
80
79
|
// Necessary for external CSS imports to work
|
|
@@ -83,10 +82,10 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
83
82
|
config: false,
|
|
84
83
|
plugins: [
|
|
85
84
|
isProd && require("cssnano")({ preset: "default" }),
|
|
86
|
-
fs.existsSync(paths.tailwind) && "tailwindcss",
|
|
87
|
-
"postcss-flexbugs-fixes",
|
|
85
|
+
fs.existsSync(paths.tailwind) && require.resolve("tailwindcss"),
|
|
86
|
+
require.resolve("postcss-flexbugs-fixes"),
|
|
88
87
|
[
|
|
89
|
-
"postcss-preset-env",
|
|
88
|
+
require.resolve("postcss-preset-env"),
|
|
90
89
|
{
|
|
91
90
|
autoprefixer: {
|
|
92
91
|
flexbox: "no-2009"
|
|
@@ -95,8 +94,8 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
95
94
|
}
|
|
96
95
|
],
|
|
97
96
|
isProd && require("./plugins/postcss-safe-area")(),
|
|
98
|
-
isProd && ["postcss-momentum-scrolling", ["scroll", "auto"]],
|
|
99
|
-
"postcss-normalize",
|
|
97
|
+
isProd && [require.resolve("postcss-momentum-scrolling"), ["scroll", "auto"]],
|
|
98
|
+
require.resolve("postcss-normalize"),
|
|
100
99
|
...override.extraPostCSSPlugins
|
|
101
100
|
].filter(Boolean)
|
|
102
101
|
},
|
|
@@ -106,7 +105,7 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
106
105
|
];
|
|
107
106
|
if (preProcessor === "less-loader") {
|
|
108
107
|
loaders.push({
|
|
109
|
-
loader: "less-loader",
|
|
108
|
+
loader: require.resolve("less-loader"),
|
|
110
109
|
options: {
|
|
111
110
|
lessOptions: {
|
|
112
111
|
javascriptEnabled: true,
|
|
@@ -208,13 +207,13 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
208
207
|
},
|
|
209
208
|
{
|
|
210
209
|
test: /\.(j|t)sx?$/,
|
|
211
|
-
loader: "babel-loader",
|
|
210
|
+
loader: require.resolve("babel-loader"),
|
|
212
211
|
exclude: /node_modules/,
|
|
213
212
|
options: require("./babel")()
|
|
214
213
|
},
|
|
215
214
|
override.transformNodeModules && {
|
|
216
215
|
test: /\.m?js$/,
|
|
217
|
-
loader: "babel-loader",
|
|
216
|
+
loader: require.resolve("babel-loader"),
|
|
218
217
|
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
|
219
218
|
options: require("./babel.dependencies")()
|
|
220
219
|
},
|
|
@@ -299,7 +298,7 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
299
298
|
test: /\.svg$/,
|
|
300
299
|
use: [
|
|
301
300
|
{
|
|
302
|
-
loader: "@svgr/webpack",
|
|
301
|
+
loader: require.resolve("@svgr/webpack"),
|
|
303
302
|
options: {
|
|
304
303
|
prettier: false,
|
|
305
304
|
svgo: false,
|
|
@@ -311,7 +310,7 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
311
310
|
}
|
|
312
311
|
},
|
|
313
312
|
{
|
|
314
|
-
loader: "url-loader",
|
|
313
|
+
loader: require.resolve("url-loader"),
|
|
315
314
|
options: {
|
|
316
315
|
limit: imageInlineSizeLimit
|
|
317
316
|
}
|
|
@@ -393,17 +392,6 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
393
392
|
optimization: {
|
|
394
393
|
minimize: isProd && override.minify !== false,
|
|
395
394
|
minimizer: [
|
|
396
|
-
override.minifyImage && new ImageMinimizerPlugin({
|
|
397
|
-
minimizer: {
|
|
398
|
-
implementation: ImageMinimizerPlugin.sharpMinify,
|
|
399
|
-
options: {
|
|
400
|
-
encodeOptions: {
|
|
401
|
-
// Your options for `sharp`
|
|
402
|
-
// https://sharp.pixelplumbing.com/api-output
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}),
|
|
407
395
|
override.minify === "esbuild" && new ESBuildMinifyPlugin({
|
|
408
396
|
pure: override.pure_funcs ?? ["console.log"],
|
|
409
397
|
drop: ["debugger"],
|
|
@@ -26,6 +26,9 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
|
|
|
26
26
|
};
|
|
27
27
|
})
|
|
28
28
|
).reduce((single, all) => all.concat(single), []);
|
|
29
|
+
if (assets.length === 0)
|
|
30
|
+
return;
|
|
31
|
+
console.log("\ngzip 后文件大小:\n");
|
|
29
32
|
assets.sort((a, b) => b.size - a.size);
|
|
30
33
|
var mainAssetIdx = assets.findIndex((asset) => /_\d+\.\d+\.\d+\./.test(asset.name));
|
|
31
34
|
assets.unshift(assets.splice(mainAssetIdx, 1)[0]);
|
|
@@ -60,6 +63,7 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
|
|
|
60
63
|
console.log(chalk.yellow("考虑下使用代码分割解决"));
|
|
61
64
|
console.log(chalk.yellow("也可以使用 npm run analyze 命令分析产物"));
|
|
62
65
|
}
|
|
66
|
+
console.log();
|
|
63
67
|
}
|
|
64
68
|
function removeFileNameHash(buildFolder, fileName) {
|
|
65
69
|
return fileName.replace(buildFolder, "").replace(/\\/g, "/").replace(/\/\d+\.\d+\.\d+\//, "/").replace(/\/?(.*)(\.[0-9a-f]+)(\.chunk)?(\.js|\.css)/, (match, p1, p2, p3, p4) => p1 + p4);
|
package/lib/utils/getOverride.js
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
|
|
1
24
|
// src/utils/getOverride.js
|
|
2
25
|
var fs = require("fs");
|
|
3
26
|
var paths = require("../config/paths");
|
|
@@ -21,5 +44,18 @@ module.exports = function getOverride() {
|
|
|
21
44
|
}
|
|
22
45
|
if (override.minify === true)
|
|
23
46
|
override.minify = defaultOverride.minify;
|
|
47
|
+
if (override.babel) {
|
|
48
|
+
const old = override.babel;
|
|
49
|
+
override.babel = (config, context) => {
|
|
50
|
+
const newConfig = old(config, context) || config;
|
|
51
|
+
let plugin = config.plugins.find(
|
|
52
|
+
(plugin2) => Array.isArray(plugin2) && /^(babel-plugin-)?import$/.test(plugin2[0])
|
|
53
|
+
);
|
|
54
|
+
if (plugin) {
|
|
55
|
+
plugin[0] = require.resolve("babel-plugin-import");
|
|
56
|
+
}
|
|
57
|
+
return newConfig;
|
|
58
|
+
};
|
|
59
|
+
}
|
|
24
60
|
return override;
|
|
25
61
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qse/edu-scripts",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.13",
|
|
4
4
|
"author": "Kinoko",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "教育工程化基础框架",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.16",
|
|
46
46
|
"@qse/ssh-sftp": "^1.0.1",
|
|
47
47
|
"@svgr/webpack": "^8.1.0",
|
|
48
|
+
"@types/express": "^4.17.21",
|
|
48
49
|
"babel-loader": "^9.2.1",
|
|
49
50
|
"babel-plugin-import": "^1.13.8",
|
|
50
51
|
"case-sensitive-paths-webpack-plugin": "^2.4.0",
|
|
@@ -61,7 +62,6 @@
|
|
|
61
62
|
"globby": "^11.1.0",
|
|
62
63
|
"gzip-size": "^6.0.0",
|
|
63
64
|
"html-webpack-plugin": "^5.6.3",
|
|
64
|
-
"image-minimizer-webpack-plugin": "^3.8.3",
|
|
65
65
|
"inquirer": "^8.2.6",
|
|
66
66
|
"less": "^3.13.1",
|
|
67
67
|
"less-loader": "^10.2.0",
|
|
@@ -81,7 +81,6 @@
|
|
|
81
81
|
"recursive-readdir": "^2.2.3",
|
|
82
82
|
"rimraf": "^3.0.2",
|
|
83
83
|
"semver": "^7.7.1",
|
|
84
|
-
"sharp": "^0.32.6",
|
|
85
84
|
"strip-ansi": "^6.0.1",
|
|
86
85
|
"style-loader": "^3.3.4",
|
|
87
86
|
"tailwindcss": "^3.4.17",
|
package/src/build.js
CHANGED
|
@@ -48,9 +48,7 @@ module.exports = async function build(args) {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
console.log(stats.toString({ colors: true, preset: 'errors-warnings', timings: true }))
|
|
51
|
-
console.log()
|
|
52
51
|
|
|
53
|
-
console.log('gzip 后文件大小:\n')
|
|
54
52
|
printFileSizesAfterBuild(
|
|
55
53
|
stats,
|
|
56
54
|
previousSizeMap,
|
|
@@ -58,7 +56,6 @@ module.exports = async function build(args) {
|
|
|
58
56
|
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
|
59
57
|
WARN_AFTER_CHUNK_GZIP_SIZE
|
|
60
58
|
)
|
|
61
|
-
console.log()
|
|
62
59
|
|
|
63
60
|
if (appConfig.single) {
|
|
64
61
|
console.log(`打包完成,可以使用 ${chalk.green('@qse/ssh-sftp')} 自动部署代码到 v1`)
|
|
@@ -21,7 +21,7 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
21
21
|
inputSourceMap: isDev,
|
|
22
22
|
presets: [
|
|
23
23
|
[
|
|
24
|
-
'@babel/preset-env',
|
|
24
|
+
require.resolve('@babel/preset-env'),
|
|
25
25
|
{
|
|
26
26
|
modules: opts.modules,
|
|
27
27
|
useBuiltIns: 'entry',
|
|
@@ -33,8 +33,9 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
33
33
|
].filter(Boolean),
|
|
34
34
|
plugins: [
|
|
35
35
|
[
|
|
36
|
-
'@babel/plugin-transform-runtime',
|
|
36
|
+
require.resolve('@babel/plugin-transform-runtime'),
|
|
37
37
|
{
|
|
38
|
+
absoluteRuntime: true,
|
|
38
39
|
corejs: false,
|
|
39
40
|
helpers: true,
|
|
40
41
|
// By default, babel assumes babel/runtime version 7.0.0-beta.0,
|
|
@@ -49,7 +50,7 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
49
50
|
},
|
|
50
51
|
],
|
|
51
52
|
[
|
|
52
|
-
'import',
|
|
53
|
+
require.resolve('babel-plugin-import'),
|
|
53
54
|
{ libraryName: 'lodash', libraryDirectory: '', camel2DashComponentName: false },
|
|
54
55
|
'lodash',
|
|
55
56
|
],
|
package/src/config/babel.js
CHANGED
|
@@ -31,7 +31,7 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
31
31
|
configFile: false,
|
|
32
32
|
presets: [
|
|
33
33
|
[
|
|
34
|
-
'@babel/preset-env',
|
|
34
|
+
require.resolve('@babel/preset-env'),
|
|
35
35
|
{
|
|
36
36
|
modules: opts.modules,
|
|
37
37
|
useBuiltIns: 'entry',
|
|
@@ -41,19 +41,20 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
41
41
|
},
|
|
42
42
|
],
|
|
43
43
|
[
|
|
44
|
-
'@babel/preset-react',
|
|
44
|
+
require.resolve('@babel/preset-react'),
|
|
45
45
|
{
|
|
46
46
|
development: isDev,
|
|
47
47
|
runtime: hasJsxRuntime ? 'automatic' : 'classic',
|
|
48
48
|
useBuiltIns: !hasJsxRuntime,
|
|
49
49
|
},
|
|
50
50
|
],
|
|
51
|
-
isTypeScriptEnabled && '@babel/preset-typescript',
|
|
51
|
+
isTypeScriptEnabled && require.resolve('@babel/preset-typescript'),
|
|
52
52
|
].filter(Boolean),
|
|
53
53
|
plugins: [
|
|
54
54
|
[
|
|
55
|
-
'@babel/plugin-transform-runtime',
|
|
55
|
+
require.resolve('@babel/plugin-transform-runtime'),
|
|
56
56
|
{
|
|
57
|
+
absoluteRuntime: true,
|
|
57
58
|
corejs: false,
|
|
58
59
|
helpers: true,
|
|
59
60
|
// By default, babel assumes babel/runtime version 7.0.0-beta.0,
|
|
@@ -67,16 +68,13 @@ module.exports = function getBabelConfig(opts = {}) {
|
|
|
67
68
|
// useESModules: true,
|
|
68
69
|
},
|
|
69
70
|
],
|
|
70
|
-
['@babel/plugin-proposal-decorators', {
|
|
71
|
-
['@babel/plugin-transform-class-properties', { loose: true }],
|
|
72
|
-
['@babel/plugin-transform-private-methods', { loose: true }],
|
|
73
|
-
['@babel/plugin-transform-private-property-in-object', { loose: true }],
|
|
71
|
+
[require.resolve('@babel/plugin-proposal-decorators'), { version: '2023-11' }],
|
|
74
72
|
[
|
|
75
|
-
'import',
|
|
73
|
+
require.resolve('babel-plugin-import'),
|
|
76
74
|
{ libraryName: 'lodash', libraryDirectory: '', camel2DashComponentName: false },
|
|
77
75
|
'lodash',
|
|
78
76
|
],
|
|
79
|
-
isDev && 'react-refresh/babel',
|
|
77
|
+
isDev && require.resolve('react-refresh/babel'),
|
|
80
78
|
addWebpackChunkName,
|
|
81
79
|
].filter(Boolean),
|
|
82
80
|
}
|
|
@@ -9,7 +9,6 @@ const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin')
|
|
|
9
9
|
const appPkg = require(paths.package)
|
|
10
10
|
const appConfig = require('../utils/appConfig')
|
|
11
11
|
const { ESBuildMinifyPlugin } = require('esbuild-loader')
|
|
12
|
-
const ImageMinimizerPlugin = require('image-minimizer-webpack-plugin')
|
|
13
12
|
const once = require('lodash/once')
|
|
14
13
|
|
|
15
14
|
const jsMainPath = appConfig.grayscale
|
|
@@ -56,18 +55,18 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
56
55
|
const getStyleLoaders = (cssOptions, preProcessor) => {
|
|
57
56
|
const loaders = [
|
|
58
57
|
{
|
|
59
|
-
loader: 'style-loader',
|
|
58
|
+
loader: require.resolve('style-loader'),
|
|
60
59
|
options: { attributes: { 'data-module': appPkg.name, 'data-version': appPkg.version } },
|
|
61
60
|
},
|
|
62
61
|
{
|
|
63
|
-
loader: 'css-loader',
|
|
62
|
+
loader: require.resolve('css-loader'),
|
|
64
63
|
options: cssOptions,
|
|
65
64
|
},
|
|
66
65
|
{
|
|
67
66
|
// Options for PostCSS as we reference these options twice
|
|
68
67
|
// Adds vendor prefixing based on your specified browser support in
|
|
69
68
|
// package.json
|
|
70
|
-
loader: 'postcss-loader',
|
|
69
|
+
loader: require.resolve('postcss-loader'),
|
|
71
70
|
options: {
|
|
72
71
|
postcssOptions: {
|
|
73
72
|
// Necessary for external CSS imports to work
|
|
@@ -76,10 +75,10 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
76
75
|
config: false,
|
|
77
76
|
plugins: [
|
|
78
77
|
isProd && require('cssnano')({ preset: 'default' }),
|
|
79
|
-
fs.existsSync(paths.tailwind) && 'tailwindcss',
|
|
80
|
-
'postcss-flexbugs-fixes',
|
|
78
|
+
fs.existsSync(paths.tailwind) && require.resolve('tailwindcss'),
|
|
79
|
+
require.resolve('postcss-flexbugs-fixes'),
|
|
81
80
|
[
|
|
82
|
-
'postcss-preset-env',
|
|
81
|
+
require.resolve('postcss-preset-env'),
|
|
83
82
|
{
|
|
84
83
|
autoprefixer: {
|
|
85
84
|
flexbox: 'no-2009',
|
|
@@ -88,8 +87,8 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
88
87
|
},
|
|
89
88
|
],
|
|
90
89
|
isProd && require('./plugins/postcss-safe-area')(),
|
|
91
|
-
isProd && ['postcss-momentum-scrolling', ['scroll', 'auto']],
|
|
92
|
-
'postcss-normalize',
|
|
90
|
+
isProd && [require.resolve('postcss-momentum-scrolling'), ['scroll', 'auto']],
|
|
91
|
+
require.resolve('postcss-normalize'),
|
|
93
92
|
...override.extraPostCSSPlugins,
|
|
94
93
|
].filter(Boolean),
|
|
95
94
|
},
|
|
@@ -99,7 +98,7 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
99
98
|
]
|
|
100
99
|
if (preProcessor === 'less-loader') {
|
|
101
100
|
loaders.push({
|
|
102
|
-
loader: 'less-loader',
|
|
101
|
+
loader: require.resolve('less-loader'),
|
|
103
102
|
options: {
|
|
104
103
|
lessOptions: {
|
|
105
104
|
javascriptEnabled: true,
|
|
@@ -208,13 +207,13 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
208
207
|
},
|
|
209
208
|
{
|
|
210
209
|
test: /\.(j|t)sx?$/,
|
|
211
|
-
loader: 'babel-loader',
|
|
210
|
+
loader: require.resolve('babel-loader'),
|
|
212
211
|
exclude: /node_modules/,
|
|
213
212
|
options: require('./babel')(),
|
|
214
213
|
},
|
|
215
214
|
override.transformNodeModules && {
|
|
216
215
|
test: /\.m?js$/,
|
|
217
|
-
loader: 'babel-loader',
|
|
216
|
+
loader: require.resolve('babel-loader'),
|
|
218
217
|
exclude: /@babel(?:\/|\\{1,2})runtime/,
|
|
219
218
|
options: require('./babel.dependencies')(),
|
|
220
219
|
},
|
|
@@ -297,7 +296,7 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
297
296
|
test: /\.svg$/,
|
|
298
297
|
use: [
|
|
299
298
|
{
|
|
300
|
-
loader: '@svgr/webpack',
|
|
299
|
+
loader: require.resolve('@svgr/webpack'),
|
|
301
300
|
options: {
|
|
302
301
|
prettier: false,
|
|
303
302
|
svgo: false,
|
|
@@ -309,7 +308,7 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
309
308
|
},
|
|
310
309
|
},
|
|
311
310
|
{
|
|
312
|
-
loader: 'url-loader',
|
|
311
|
+
loader: require.resolve('url-loader'),
|
|
313
312
|
options: {
|
|
314
313
|
limit: imageInlineSizeLimit,
|
|
315
314
|
},
|
|
@@ -397,18 +396,6 @@ module.exports = function getWebpackConfig(args, override) {
|
|
|
397
396
|
optimization: {
|
|
398
397
|
minimize: isProd && override.minify !== false,
|
|
399
398
|
minimizer: [
|
|
400
|
-
override.minifyImage &&
|
|
401
|
-
new ImageMinimizerPlugin({
|
|
402
|
-
minimizer: {
|
|
403
|
-
implementation: ImageMinimizerPlugin.sharpMinify,
|
|
404
|
-
options: {
|
|
405
|
-
encodeOptions: {
|
|
406
|
-
// Your options for `sharp`
|
|
407
|
-
// https://sharp.pixelplumbing.com/api-output
|
|
408
|
-
},
|
|
409
|
-
},
|
|
410
|
-
},
|
|
411
|
-
}),
|
|
412
399
|
override.minify === 'esbuild' &&
|
|
413
400
|
new ESBuildMinifyPlugin({
|
|
414
401
|
pure: override.pure_funcs ?? ['console.log'],
|
|
@@ -50,6 +50,11 @@ function printFileSizesAfterBuild(
|
|
|
50
50
|
})
|
|
51
51
|
)
|
|
52
52
|
.reduce((single, all) => all.concat(single), [])
|
|
53
|
+
|
|
54
|
+
if (assets.length === 0) return
|
|
55
|
+
|
|
56
|
+
console.log('\ngzip 后文件大小:\n')
|
|
57
|
+
|
|
53
58
|
assets.sort((a, b) => b.size - a.size)
|
|
54
59
|
|
|
55
60
|
// move main file to first
|
|
@@ -91,6 +96,8 @@ function printFileSizesAfterBuild(
|
|
|
91
96
|
console.log(chalk.yellow('考虑下使用代码分割解决'))
|
|
92
97
|
console.log(chalk.yellow('也可以使用 npm run analyze 命令分析产物'))
|
|
93
98
|
}
|
|
99
|
+
|
|
100
|
+
console.log()
|
|
94
101
|
}
|
|
95
102
|
|
|
96
103
|
function removeFileNameHash(buildFolder, fileName) {
|
package/src/utils/getOverride.js
CHANGED
|
@@ -29,5 +29,20 @@ module.exports = function getOverride() {
|
|
|
29
29
|
|
|
30
30
|
if (override.minify === true) override.minify = defaultOverride.minify
|
|
31
31
|
|
|
32
|
+
if (override.babel) {
|
|
33
|
+
const old = override.babel
|
|
34
|
+
override.babel = (config, context) => {
|
|
35
|
+
const newConfig = old(config, context) || config
|
|
36
|
+
|
|
37
|
+
let plugin = config.plugins.find(
|
|
38
|
+
(plugin) => Array.isArray(plugin) && /^(babel-plugin-)?import$/.test(plugin[0])
|
|
39
|
+
)
|
|
40
|
+
if (plugin) {
|
|
41
|
+
plugin[0] = require.resolve('babel-plugin-import')
|
|
42
|
+
}
|
|
43
|
+
return newConfig
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
32
47
|
return override
|
|
33
48
|
}
|