@vnejs/build 0.0.32 → 0.0.34
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 +24 -19
- package/src/client/webpack.config.js +78 -41
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vnejs/build",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.34",
|
|
4
4
|
"description": "Build tools for @vnejs",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -15,30 +15,35 @@
|
|
|
15
15
|
"keywords": [],
|
|
16
16
|
"author": "",
|
|
17
17
|
"license": "ISC",
|
|
18
|
+
"browserslist": {
|
|
19
|
+
"production": [
|
|
20
|
+
">0.5%",
|
|
21
|
+
"not dead",
|
|
22
|
+
"not op_mini all"
|
|
23
|
+
],
|
|
24
|
+
"development": [
|
|
25
|
+
"last 1 chrome version",
|
|
26
|
+
"last 1 firefox version",
|
|
27
|
+
"last 1 safari version"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
18
30
|
"dependencies": {
|
|
19
31
|
"commander": "13.1.0",
|
|
20
32
|
"@bem-react/classname": "1.5.12",
|
|
21
33
|
"lodash.merge": "4.6.2",
|
|
22
|
-
"webpack": "
|
|
23
|
-
"html-webpack-plugin": "
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"stylus": "0.59.0",
|
|
28
|
-
"stylus-loader": "3.0.2",
|
|
29
|
-
"css-loader": "5.0.0",
|
|
34
|
+
"webpack": "5.107.2",
|
|
35
|
+
"html-webpack-plugin": "5.6.7",
|
|
36
|
+
"core-js": "3.49.0",
|
|
37
|
+
"style-loader": "4.0.0",
|
|
38
|
+
"css-loader": "7.1.4",
|
|
30
39
|
"react": "~19.2.7",
|
|
31
40
|
"react-dom": "~19.2.7",
|
|
32
|
-
"
|
|
33
|
-
"@loadable/webpack-plugin": "5.14.0",
|
|
34
|
-
"babel-loader": "8.1.0",
|
|
35
|
-
"babel-plugin-module-resolver": "4.0.0",
|
|
36
|
-
"babel-plugin-transform-react-remove-prop-types": "0.4.24",
|
|
41
|
+
"babel-loader": "10.1.1",
|
|
37
42
|
"base64-inline-loader": "2.0.1",
|
|
38
|
-
"@babel/core": "7.
|
|
39
|
-
"@babel/plugin-
|
|
40
|
-
"@babel/
|
|
41
|
-
"@babel/preset-
|
|
42
|
-
"@babel/preset-
|
|
43
|
+
"@babel/core": "7.29.7",
|
|
44
|
+
"@babel/plugin-transform-class-properties": "7.29.7",
|
|
45
|
+
"@babel/preset-env": "7.29.7",
|
|
46
|
+
"@babel/preset-react": "7.29.7",
|
|
47
|
+
"@babel/preset-typescript": "7.29.7"
|
|
43
48
|
}
|
|
44
49
|
}
|
|
@@ -2,41 +2,72 @@ const fs = require("fs");
|
|
|
2
2
|
const path = require("path");
|
|
3
3
|
const webpack = require("webpack");
|
|
4
4
|
const HtmlWebpackPlugin = require("html-webpack-plugin");
|
|
5
|
-
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
6
5
|
|
|
6
|
+
const buildRoot = path.join(__dirname, "../..");
|
|
7
|
+
const entryDir = "entry";
|
|
7
8
|
const isDev = process.env.NODE_ENV === "development";
|
|
8
9
|
|
|
9
|
-
const
|
|
10
|
+
const vnejsPattern = `${path.sep}node_modules${path.sep}@vnejs${path.sep}`;
|
|
11
|
+
|
|
12
|
+
const shouldBabelTranspile = (resourcePath) => {
|
|
13
|
+
if (resourcePath.includes(`${path.sep}node_modules${path.sep}`)) {
|
|
14
|
+
if (!resourcePath.includes(vnejsPattern)) return false;
|
|
15
|
+
|
|
16
|
+
return !/[\\/]dist[\\/]/.test(resourcePath);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return true;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const getScriptLoader = () => ({
|
|
10
23
|
loader: `babel-loader`,
|
|
11
24
|
options: {
|
|
12
|
-
|
|
25
|
+
root: buildRoot,
|
|
26
|
+
plugins: [`@babel/plugin-transform-class-properties`],
|
|
13
27
|
presets: [
|
|
28
|
+
[`@babel/preset-typescript`, { allowDeclareFields: true }],
|
|
14
29
|
[`@babel/preset-react`, { runtime: "automatic" }],
|
|
15
|
-
[`@babel/preset-env`, {
|
|
30
|
+
[`@babel/preset-env`, { bugfixes: true, corejs: 3, modules: "commonjs", useBuiltIns: `usage` }],
|
|
16
31
|
],
|
|
17
32
|
cacheDirectory: true,
|
|
18
33
|
caller: { target: "clientside", name: "babel-loader" },
|
|
19
34
|
},
|
|
20
35
|
});
|
|
21
36
|
|
|
22
|
-
const getCssLoader = (
|
|
23
|
-
// MiniCssExtractPlugin.loader,
|
|
24
|
-
{ loader: `style-loader` },
|
|
25
|
-
{ loader: `css-loader` },
|
|
26
|
-
];
|
|
37
|
+
const getCssLoader = () => [{ loader: `style-loader` }, { loader: `css-loader` }];
|
|
27
38
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
const getVnejsScopedPackageNames = (rootPath, scopePrefix) => {
|
|
40
|
+
let dir = rootPath;
|
|
41
|
+
|
|
42
|
+
while (dir !== path.dirname(dir)) {
|
|
43
|
+
const scopedDir = path.join(dir, "node_modules", "@vnejs");
|
|
44
|
+
|
|
45
|
+
if (fs.existsSync(scopedDir)) {
|
|
46
|
+
return fs
|
|
47
|
+
.readdirSync(scopedDir)
|
|
48
|
+
.filter((name) => name.startsWith(scopePrefix))
|
|
49
|
+
.map((name) => `@vnejs/${name}`)
|
|
50
|
+
.filter((packageName) => {
|
|
51
|
+
try {
|
|
52
|
+
require.resolve(`${packageName}/package.json`, { paths: [rootPath] });
|
|
53
|
+
return true;
|
|
54
|
+
} catch {
|
|
55
|
+
return false;
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
.sort();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
dir = path.dirname(dir);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return [];
|
|
65
|
+
};
|
|
34
66
|
|
|
35
67
|
module.exports = (rootPath, options) => {
|
|
36
68
|
const distPath = path.join(rootPath, "dist");
|
|
37
69
|
const gamePath = path.join(rootPath, "game");
|
|
38
|
-
const
|
|
39
|
-
const entry = [path.join(rootPath, "client", "index.js")];
|
|
70
|
+
const entry = [path.join(rootPath, entryDir, "index.js")];
|
|
40
71
|
|
|
41
72
|
fs.readdirSync(gamePath).forEach((modDir) => {
|
|
42
73
|
const scriptPath = path.join(gamePath, modDir, "scripts", "index.js");
|
|
@@ -46,42 +77,48 @@ module.exports = (rootPath, options) => {
|
|
|
46
77
|
|
|
47
78
|
const resolvePackageDir = (name) => path.dirname(require.resolve(`${name}/package.json`, { paths: [rootPath] }));
|
|
48
79
|
|
|
80
|
+
const uisPackages = getVnejsScopedPackageNames(rootPath, "uis.");
|
|
81
|
+
const bundlePackages = getVnejsScopedPackageNames(rootPath, "bundles.");
|
|
82
|
+
|
|
83
|
+
const indexDependOn = ["vendors"];
|
|
84
|
+
|
|
85
|
+
uisPackages.length && indexDependOn.push("uis");
|
|
86
|
+
bundlePackages.length && indexDependOn.push("bundle");
|
|
87
|
+
|
|
88
|
+
const htmlChunks = [...indexDependOn, "index"];
|
|
89
|
+
|
|
90
|
+
const webpackEntry = { index: { import: entry, chunkLoading: false, dependOn: indexDependOn }, vendors: [`react`, `react-dom`, `@bem-react/classname`] };
|
|
91
|
+
|
|
92
|
+
uisPackages.length && (webpackEntry.uis = { import: uisPackages, dependOn: "vendors" });
|
|
93
|
+
|
|
94
|
+
if (bundlePackages.length) {
|
|
95
|
+
const bundleDependOn = ["vendors"];
|
|
96
|
+
|
|
97
|
+
uisPackages.length && bundleDependOn.push("uis");
|
|
98
|
+
|
|
99
|
+
webpackEntry.bundle = { import: bundlePackages, dependOn: bundleDependOn };
|
|
100
|
+
}
|
|
101
|
+
|
|
49
102
|
return {
|
|
50
103
|
watch: options.watch,
|
|
51
104
|
mode: isDev ? "development" : "production",
|
|
52
105
|
target: "web",
|
|
53
|
-
entry:
|
|
54
|
-
index: { import: entry, chunkLoading: false, dependOn: "vendors" },
|
|
55
|
-
vendors: [`regenerator-runtime`, `react`, `react-dom`, `@bem-react/classname`],
|
|
56
|
-
},
|
|
106
|
+
entry: webpackEntry,
|
|
57
107
|
optimization: { minimize: true },
|
|
58
108
|
resolve: {
|
|
59
|
-
extensions: [".js", ".jsx", ".ts", ".tsx", ".
|
|
60
|
-
alias: {
|
|
61
|
-
react: resolvePackageDir("react"),
|
|
62
|
-
"react-dom": resolvePackageDir("react-dom"),
|
|
63
|
-
},
|
|
109
|
+
extensions: [".js", ".jsx", ".ts", ".tsx", ".css"],
|
|
110
|
+
alias: { "react": resolvePackageDir("react"), "react-dom": resolvePackageDir("react-dom") },
|
|
64
111
|
},
|
|
65
|
-
output: { path: distPath, filename: "[name].[
|
|
112
|
+
output: { path: distPath, filename: "[name].[contenthash].js" },
|
|
66
113
|
plugins: [
|
|
67
|
-
new webpack.DefinePlugin({
|
|
68
|
-
|
|
69
|
-
}),
|
|
70
|
-
new HtmlWebpackPlugin({
|
|
71
|
-
filename: "index.html",
|
|
72
|
-
template: path.join(rootPath, "client", "index.html"),
|
|
73
|
-
chunks: ["vendors", "index"],
|
|
74
|
-
chunksSortMode: "manual",
|
|
75
|
-
}),
|
|
76
|
-
new MiniCssExtractPlugin({ filename: "index.css" }),
|
|
114
|
+
new webpack.DefinePlugin({ "process.env.NODE_ENV": `"${isDev ? "development" : "production"}"` }),
|
|
115
|
+
new HtmlWebpackPlugin({ filename: "index.html", template: path.join(rootPath, entryDir, "index.html"), chunks: htmlChunks, chunksSortMode: "manual" }),
|
|
77
116
|
],
|
|
78
117
|
|
|
79
118
|
module: {
|
|
80
119
|
rules: [
|
|
81
|
-
{ test: /\.m?(t|j)sx?$/,
|
|
82
|
-
{ test: /\.
|
|
83
|
-
{ test: /\.css$/, use: getCssLoader(nodeModulesPath) },
|
|
84
|
-
{ test: /\.styl$/, use: getStylusLoader(nodeModulesPath) },
|
|
120
|
+
{ test: /\.m?(t|j)sx?$/, exclude: (resourcePath) => !shouldBabelTranspile(resourcePath), use: getScriptLoader() },
|
|
121
|
+
{ test: /\.css$/, use: getCssLoader() },
|
|
85
122
|
{
|
|
86
123
|
test: /\.(ttf|eot|woff2?)$/,
|
|
87
124
|
type: "asset/resource",
|