@vnejs/build 0.0.33 → 0.0.35

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vnejs/build",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
4
4
  "description": "Build tools for @vnejs",
5
5
  "main": "src/index.js",
6
6
  "bin": {
@@ -15,28 +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": "^5.88.1",
23
- "html-webpack-plugin": "4.5.2",
24
- "mini-css-extract-plugin": "1.1.1",
25
- "regenerator-runtime": "0.13.7",
26
- "style-loader": "2.0.0",
27
- "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",
28
39
  "react": "~19.2.7",
29
40
  "react-dom": "~19.2.7",
30
- "@loadable/babel-plugin": "5.13.2",
31
- "@loadable/webpack-plugin": "5.14.0",
32
- "babel-loader": "8.1.0",
33
- "babel-plugin-module-resolver": "4.0.0",
34
- "babel-plugin-transform-react-remove-prop-types": "0.4.24",
41
+ "babel-loader": "10.1.1",
35
42
  "base64-inline-loader": "2.0.1",
36
- "@babel/core": "7.12.3",
37
- "@babel/plugin-proposal-class-properties": "7.12.1",
38
- "@babel/plugin-syntax-dynamic-import": "7.8.3",
39
- "@babel/preset-env": "7.12.1",
40
- "@babel/preset-react": "7.12.1"
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"
41
48
  }
42
49
  }
@@ -2,34 +2,76 @@ 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 getScriptLoader = (nodeModulesPath) => ({
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
- plugins: [`@babel/plugin-syntax-dynamic-import`, `@babel/plugin-proposal-class-properties`, `@loadable/babel-plugin`],
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`, { useBuiltIns: "entry", corejs: "core-js@3", modules: "commonjs" }],
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 = (nodeModulesPath) => [
23
- // MiniCssExtractPlugin.loader,
24
- { loader: `style-loader` },
25
- { loader: `css-loader` },
26
- ];
37
+ const getCssLoader = () => [{ loader: `style-loader` }, { loader: `css-loader` }];
38
+
39
+ const webpackChunkPattern = /^(index|vendors|uis|bundle)\.[a-f0-9]+\.js$/;
40
+
41
+ const isWebpackOutput = (asset) => asset === "index.html" || webpackChunkPattern.test(asset) || asset.startsWith("assets/");
42
+
43
+ const getVnejsScopedPackageNames = (rootPath, scopePrefix) => {
44
+ let dir = rootPath;
45
+
46
+ while (dir !== path.dirname(dir)) {
47
+ const scopedDir = path.join(dir, "node_modules", "@vnejs");
48
+
49
+ if (fs.existsSync(scopedDir)) {
50
+ return fs
51
+ .readdirSync(scopedDir)
52
+ .filter((name) => name.startsWith(scopePrefix))
53
+ .map((name) => `@vnejs/${name}`)
54
+ .filter((packageName) => {
55
+ try {
56
+ require.resolve(`${packageName}/package.json`, { paths: [rootPath] });
57
+ return true;
58
+ } catch {
59
+ return false;
60
+ }
61
+ })
62
+ .sort();
63
+ }
64
+
65
+ dir = path.dirname(dir);
66
+ }
67
+
68
+ return [];
69
+ };
27
70
 
28
71
  module.exports = (rootPath, options) => {
29
72
  const distPath = path.join(rootPath, "dist");
30
73
  const gamePath = path.join(rootPath, "game");
31
- const nodeModulesPath = path.join(rootPath, "node_modules");
32
- const entry = [path.join(rootPath, "client", "index.js")];
74
+ const entry = [path.join(rootPath, entryDir, "index.js")];
33
75
 
34
76
  fs.readdirSync(gamePath).forEach((modDir) => {
35
77
  const scriptPath = path.join(gamePath, modDir, "scripts", "index.js");
@@ -39,41 +81,52 @@ module.exports = (rootPath, options) => {
39
81
 
40
82
  const resolvePackageDir = (name) => path.dirname(require.resolve(`${name}/package.json`, { paths: [rootPath] }));
41
83
 
84
+ const uisPackages = getVnejsScopedPackageNames(rootPath, "uis.");
85
+ const bundlePackages = getVnejsScopedPackageNames(rootPath, "bundles.");
86
+
87
+ const indexDependOn = ["vendors"];
88
+
89
+ uisPackages.length && indexDependOn.push("uis");
90
+ bundlePackages.length && indexDependOn.push("bundle");
91
+
92
+ const htmlChunks = [...indexDependOn, "index"];
93
+
94
+ const webpackEntry = { index: { import: entry, chunkLoading: false, dependOn: indexDependOn }, vendors: [`react`, `react-dom`, `@bem-react/classname`] };
95
+
96
+ uisPackages.length && (webpackEntry.uis = { import: uisPackages, dependOn: "vendors" });
97
+
98
+ if (bundlePackages.length) {
99
+ const bundleDependOn = ["vendors"];
100
+
101
+ uisPackages.length && bundleDependOn.push("uis");
102
+
103
+ webpackEntry.bundle = { import: bundlePackages, dependOn: bundleDependOn };
104
+ }
105
+
42
106
  return {
43
107
  watch: options.watch,
44
108
  mode: isDev ? "development" : "production",
45
109
  target: "web",
46
- entry: {
47
- index: { import: entry, chunkLoading: false, dependOn: "vendors" },
48
- vendors: [`regenerator-runtime`, `react`, `react-dom`, `@bem-react/classname`],
49
- },
110
+ entry: webpackEntry,
50
111
  optimization: { minimize: true },
51
112
  resolve: {
52
113
  extensions: [".js", ".jsx", ".ts", ".tsx", ".css"],
53
- alias: {
54
- react: resolvePackageDir("react"),
55
- "react-dom": resolvePackageDir("react-dom"),
56
- },
114
+ alias: { "react": resolvePackageDir("react"), "react-dom": resolvePackageDir("react-dom") },
115
+ },
116
+ output: {
117
+ path: distPath,
118
+ filename: "[name].[contenthash].js",
119
+ clean: { keep: (asset) => !isWebpackOutput(asset) },
57
120
  },
58
- output: { path: distPath, filename: "[name].[hash].js" },
59
121
  plugins: [
60
- new webpack.DefinePlugin({
61
- "process.env.NODE_ENV": `"${isDev ? "development" : "production"}"`,
62
- }),
63
- new HtmlWebpackPlugin({
64
- filename: "index.html",
65
- template: path.join(rootPath, "client", "index.html"),
66
- chunks: ["vendors", "index"],
67
- chunksSortMode: "manual",
68
- }),
69
- new MiniCssExtractPlugin({ filename: "index.css" }),
122
+ new webpack.DefinePlugin({ "process.env.NODE_ENV": `"${isDev ? "development" : "production"}"` }),
123
+ new HtmlWebpackPlugin({ filename: "index.html", template: path.join(rootPath, entryDir, "index.html"), chunks: htmlChunks, chunksSortMode: "manual" }),
70
124
  ],
71
125
 
72
126
  module: {
73
127
  rules: [
74
- { test: /\.m?(t|j)sx?$/, include: path.join(nodeModulesPath, "@vnejs"), use: getScriptLoader(nodeModulesPath) },
75
- { test: /\.m?(t|j)sx?$/, exclude: /node_modules/, use: getScriptLoader(nodeModulesPath) },
76
- { test: /\.css$/, use: getCssLoader(nodeModulesPath) },
128
+ { test: /\.m?(t|j)sx?$/, exclude: (resourcePath) => !shouldBabelTranspile(resourcePath), use: getScriptLoader() },
129
+ { test: /\.css$/, use: getCssLoader() },
77
130
  {
78
131
  test: /\.(ttf|eot|woff2?)$/,
79
132
  type: "asset/resource",
package/src/data/index.js CHANGED
@@ -22,17 +22,19 @@ const buildDataFunc = (gameDir, distDir) => {
22
22
  fs.writeFileSync(path.join(distDir, "mods.json"), JSON.stringify(fs.readdirSync(gameDir)));
23
23
  };
24
24
 
25
- const recreateDist = (distDir) => {
26
- fs.rmSync(distDir, { recursive: true, force: true });
27
- fs.mkdirSync(distDir);
25
+ const cleanJsonFiles = (distDir) => {
26
+ fs.mkdirSync(distDir, { recursive: true });
27
+
28
+ fs.readdirSync(distDir).forEach((file) => {
29
+ file.endsWith(".json") && fs.rmSync(path.join(distDir, file), { force: true });
30
+ });
28
31
  };
29
32
 
30
33
  module.exports = (rootDir) => (options) => {
31
34
  const gameDir = path.join(rootDir, "game");
32
35
  const distDir = path.join(rootDir, "dist");
33
36
 
34
- recreateDist(distDir);
35
-
37
+ cleanJsonFiles(distDir);
36
38
  buildDataFunc(gameDir, distDir);
37
39
 
38
40
  options.watch && fs.watch(gameDir, { recursive: true }, (eventType, filename) => filename && buildDataFunc(gameDir, distDir));