wb-lib-tool 0.0.1-beta.2 → 0.0.1-beta.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.
@@ -91,6 +91,9 @@ export default {
91
91
 
92
92
  ###### 使用lib.config.js
93
93
  ```
94
+ const path = require('path');
95
+ const { merge } = require('webpack-merge');
96
+
94
97
  module.exports = {
95
98
  compileDir: 'src/components', // 默认编译目录
96
99
  output: 'lib', // 输出存放文件夹
package/bin/dev.js CHANGED
@@ -1,11 +1,12 @@
1
+ const webpackDevServerPath = require.resolve('webpack-dev-server/bin/webpack-dev-server');
1
2
  const { spawnPromise } = require('../utils/util.js');
2
3
  const { getResolvePath } = require('../utils/file.js');
3
4
 
4
5
  const spawnDev = async () => {
5
- await spawnPromise('webpack-dev-server', ['--config',
6
+ await spawnPromise(webpackDevServerPath, ['--config',
6
7
  `${getResolvePath('config/webpack.dev.conf.js')}`,
7
8
  '--progress',
8
9
  ...process.argv.slice(3),
9
- ], { stdio: 'inherit' });
10
+ ]);
10
11
  }
11
12
  spawnDev();
package/bin/index.js CHANGED
@@ -6,7 +6,6 @@ const packageJson = require('../package.json');
6
6
 
7
7
  const program = new Command(packageJson.name);
8
8
 
9
-
10
9
  program.version(packageJson.version);
11
10
  program.command('lib').action(() => {
12
11
  require('./lib.js');
@@ -19,16 +18,6 @@ program.command('clean').option('-n, --name <name>', '删除项目内的文件
19
18
  });
20
19
  program.parse();
21
20
 
22
- // 处理程序退出
23
- // const handleExit = (exitStatus = 0) => {
24
- // console.error(chalk.red(
25
- // `进程异常退出.\n`
26
- // ));
27
- // // 确保exitStatus是数字类型
28
- // const numericExitStatus = typeof exitStatus === 'number' ? exitStatus : 1;
29
- // process.exit(numericExitStatus);
30
- // }
31
-
32
21
  // 处理打印错误信息
33
22
  const handleError = (error, _exitStatus = 1) => {
34
23
  console.log('')
@@ -36,10 +25,6 @@ const handleError = (error, _exitStatus = 1) => {
36
25
  `进程出错! \n` +
37
26
  `${error ? (error.message || error) : ''}`
38
27
  ));
39
- // handleExit(exitStatus);
40
28
  }
41
29
 
42
- // process.on('SIGINT', handleExit); // 终止监听
43
- // process.on('SIGTERM', handleExit); // 终止监听
44
30
  process.on('uncaughtException', (error) => handleError(error, 1)); // 异常监听
45
- // process.on('unhandledRejection', (reason, _promise) => handleError(reason, 1)); // 异常监听
package/bin/lib.js CHANGED
@@ -1,8 +1,8 @@
1
1
  const chalk = require('chalk');
2
+ const webpackPath = require.resolve('webpack/bin/webpack');
2
3
  const { timestampToHMS, DateTimeDiffS, spawnPromise, isObject } = require('../utils/util.js');
3
4
  const { getResolvePath, getCustomConfig, removeFile } = require('../utils/file.js');
4
5
  const { OUTPUT } = require('../config/PATH.js');
5
-
6
6
  const customConfig = getCustomConfig();
7
7
 
8
8
  const output = customConfig && customConfig.outputDir ? customConfig.outputDir : OUTPUT;
@@ -17,7 +17,7 @@ const spawnBuildLib = async () => {
17
17
  console.log(' ');
18
18
  if (Array.isArray(format)) {
19
19
  isRun = true;
20
- await Promise.all(format.map(type => spawnPromise('webpack', [
20
+ await Promise.all(format.map(type => spawnPromise(webpackPath, [
21
21
  '--config',
22
22
  `${getResolvePath('config/webpack.lib.conf.js')}`,
23
23
  '--progress', '--color',
@@ -25,10 +25,10 @@ const spawnBuildLib = async () => {
25
25
  `format=${type}`,
26
26
  `output=${output}`,
27
27
  ...process.argv.slice(3),
28
- ], { stdio: 'inherit' })));
28
+ ])));
29
29
  } else if (isObject(format)) {
30
30
  isRun = true;
31
- await Promise.all(Object.keys(format).map(key => spawnPromise('webpack', [
31
+ await Promise.all(Object.keys(format).map(key => spawnPromise(webpackPath, [
32
32
  '--config',
33
33
  `${getResolvePath('config/webpack.lib.conf.js')}`,
34
34
  '--progress', '--color',
@@ -37,17 +37,17 @@ const spawnBuildLib = async () => {
37
37
  `libName=${format[key]}`,
38
38
  `output=${output}`,
39
39
  ...process.argv.slice(3),
40
- ], { stdio: 'inherit' })));
40
+ ])));
41
41
  }
42
42
  if (!isRun || isMerageAll) {
43
- await spawnPromise('webpack', ['--config',
43
+ await spawnPromise(webpackPath, ['--config',
44
44
  `${getResolvePath('config/webpack.lib.conf.js')}`,
45
45
  '--progress', '--color',
46
46
  '--env', 'formatType=String',
47
47
  format && `format=${format}`,
48
48
  `output=${output}`,
49
49
  ...process.argv.slice(3),
50
- ], { stdio: 'inherit' });
50
+ ]);
51
51
  }
52
52
  console.log(' ');
53
53
  console.log(chalk.green(`执行结束: ${timestampToHMS(Date.now())}, 耗时: ${DateTimeDiffS(Date.now(), startTime)}`));
@@ -1,5 +1,6 @@
1
1
  const { getResolvePath } = require('../utils/file');
2
2
  const MiniCssExtractPlugin = require('mini-css-extract-plugin');
3
+ const babelLoader = require.resolve('babel-loader');
3
4
 
4
5
  const baseConfig = (env) => {
5
6
  const isDev = env === 'development';
@@ -81,7 +82,7 @@ const baseConfig = (env) => {
81
82
  exclude: /node_modules/,
82
83
  use: [
83
84
  {
84
- loader: 'babel-loader',
85
+ loader: babelLoader,
85
86
  options: {
86
87
  configFile: getResolvePath('babel.config.json', __dirname),
87
88
  },
@@ -40,7 +40,7 @@ const getLibConfig = function ({
40
40
  'react-router-dom': 'react-router-dom',
41
41
  },
42
42
  optimization: {
43
- minimize: false, // 是否开启压缩
43
+ minimize: true, // 是否开启压缩
44
44
  moduleIds: 'deterministic',
45
45
  minimizer: [
46
46
  new TerserPlugin({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wb-lib-tool",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.4",
4
4
  "description": "基于webpack库模式编译生成组件库",
5
5
  "license": "MIT",
6
6
  "readme": "README.ch.md",
@@ -63,6 +63,7 @@
63
63
  "sass": "^1.93.2",
64
64
  "sass-loader": "^16.0.6",
65
65
  "style-loader": "^4.0.0",
66
+ "terser-webpack-plugin": "^5.3.16",
66
67
  "ts-node": "^10.9.2",
67
68
  "typescript": "^5.9.3",
68
69
  "webpack": "^5.102.1",
@@ -78,7 +79,7 @@
78
79
  "wb-lib-tool": "^0.0.1-beta.1"
79
80
  },
80
81
  "engines": {
81
- "node": ">16.18"
82
+ "node": ">=16.18"
82
83
  },
83
84
  "peerDependencies": {
84
85
  "webpack": ">=5"
@@ -86,5 +87,15 @@
86
87
  "overrides": {
87
88
  "react": "$react",
88
89
  "react-dom": "$react-dom"
90
+ },
91
+ "pnpm": {
92
+ "onlyBuiltDependencies": [
93
+ "@parcel/watcher",
94
+ "@swc/core",
95
+ "core-js",
96
+ "core-js",
97
+ "esbuild",
98
+ "less"
99
+ ]
89
100
  }
90
101
  }
package/utils/file.js CHANGED
@@ -7,7 +7,7 @@ const {
7
7
  } = require('path');
8
8
  const { readdirSync, statSync, existsSync } = require('fs');
9
9
  const { rimraf } = require('rimraf');
10
- const { getTsFileExportContent } = require('./getTsContent.js');
10
+ const { getFileExportContent } = require('./getFileContent.js');
11
11
  const { ROOT, BUILD_FILE_NAME } = require('../config/PATH.js');
12
12
 
13
13
  // 查询将要使用的文件是否存在
@@ -124,21 +124,10 @@ const getCustomConfig = () => {
124
124
  if (!checkFileExist(buildConfigPath)) continue;
125
125
  let conf = null;
126
126
  try {
127
- if (extnamePath(buildConfigPath) === '.js') {
128
- // 清除缓存,确保每次都重新加载文件
129
- if (require.cache[require.resolve(buildConfigPath)]) {
130
- delete require.cache[require.resolve(buildConfigPath)];
131
- }
132
- // 直接使用require加载配置文件
133
- conf = require(buildConfigPath);
134
- // 如果是ES模块导出,提取default属性
135
- conf = conf.default || conf;
136
- } else {
137
- conf = getTsFileExportContent(buildConfigPath);
138
- }
127
+ conf = getFileExportContent(buildConfigPath);
139
128
  return conf;
140
129
  } catch (error) {
141
- console.error(' 配置文件加载失败 => \n', error);
130
+ console.error(' 配置文件加载失败 => \n', error, '\n');
142
131
  continue;
143
132
  }
144
133
  }
@@ -1,4 +1,4 @@
1
- const getTsFileExportContent = (filePath) => {
1
+ const getFileExportContent = (filePath) => {
2
2
  if (!filePath) return null;
3
3
  let exports = null;
4
4
  require('ts-node').register({
@@ -11,10 +11,10 @@ const getTsFileExportContent = (filePath) => {
11
11
  }
12
12
  });
13
13
  // 直接加载原文件,自动处理所有依赖
14
- exports = require(filePath).default; // 取 export default
14
+ exports = require(filePath).default || require(filePath); // 取 export default
15
15
  return exports;
16
16
  }
17
17
 
18
18
  module.exports = {
19
- getTsFileExportContent
19
+ getFileExportContent
20
20
  }
package/utils/util.js CHANGED
@@ -22,7 +22,7 @@ const DateTimeDiffS = (endTime, startTime) => {
22
22
  // spawn promise 封装
23
23
  const spawnPromise = (command, args, options = {}) => {
24
24
  return new Promise((resolve, reject) => {
25
- const cross = spawn(command, args, options);
25
+ const cross = spawn(command, args, Object.assign({ stdio: 'inherit' }, options));
26
26
  cross.on('close', (code) => {
27
27
  if (code != 0) {
28
28
  return reject(new Error(`进程[${command}]命令执行失败:退出码 ${code}`));