qmzreact 1.0.13 → 1.0.14

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/conf/utils.js CHANGED
@@ -1,76 +1,81 @@
1
- var path = require('path')
2
- var fs = require('fs')
3
- var { cosmiconfigSync } = require('cosmiconfig');
4
-
5
- function isObj(obj) {
6
- return Object.prototype.toString.call(obj) === '[object Object]'
7
- }
8
-
9
- /**
10
- * 获取用户配置信息
11
- * 该函数尝试从指定位置加载构建配置文件
12
- * 如果配置文件不存在或无效,则使用空对象作为默认配置
13
- */
14
- function getUserConfig() {
15
- var explorer = cosmiconfigSync('build', { searchPlaces: ['build.config.js'] });
16
- var userBuildConfig = {};
17
- try {
18
- var result = explorer.load(rootPath('build.config.js'));
19
- if (
20
- result &&
21
- result.config &&
22
- isObj(result.config)
23
- ) {
24
- userBuildConfig = result.config;
25
- }
26
- } catch (e) {
27
- // ignore
28
- }
29
- return userBuildConfig;
30
- }
31
-
32
- /*
33
- * 返回静态资源路径(不需要被处理的资源)
34
- * project/static
35
- * */
36
- function assetsPath(_path) {
37
- return path.posix.join('', _path)
38
- }
39
-
40
- function rootPath(_path) {
41
- return path.join(process.cwd(), _path)
42
- }
43
-
44
- // 监听webpack监控以外的文件重启服务
45
- function getWatchFileRestartService(pathname, restartService) {
46
- let isFileRename = false
47
- fs.access(pathname, fs.constants.F_OK, (err) => {
48
- if (!err) {
49
- fs.watch(pathname, (eventType, filename) => {
50
- if (eventType == 'rename') {
51
- isFileRename = true
52
- }
53
- if (isFileRename) {
54
- // 检查文件
55
- // 新增文件 且存在 index 的入口文件时 重启服务
56
- ['./index.ts', './index.tsx', './index.js', './index.jsx'].forEach(file => {
57
- fs.access(path.join(pathname, filename, file), fs.constants.F_OK, (err) => {
58
- if (!err) {
59
- isFileRename = false;
60
- typeof restartService === 'function' && restartService();
61
- }
62
- });
63
- })
64
- }
65
- })
66
- }
67
- });
68
- }
69
-
70
- module.exports = {
71
- getWatchFileRestartService,
72
- rootPath,
73
- assetsPath,
74
- getUserConfig,
75
- isObj
1
+ var path = require('path')
2
+ var fs = require('fs')
3
+ var { cosmiconfigSync } = require('cosmiconfig');
4
+
5
+ var configFilePath = 'build.config.js';
6
+
7
+ function isObj(obj) {
8
+ return Object.prototype.toString.call(obj) === '[object Object]'
9
+ }
10
+
11
+ /**
12
+ * 获取用户配置信息
13
+ * 该函数尝试从指定位置加载构建配置文件
14
+ * 如果配置文件不存在或无效,则使用空对象作为默认配置
15
+ */
16
+ function getUserConfig() {
17
+ var explorer = cosmiconfigSync('build', { searchPlaces: [configFilePath] });
18
+ var userBuildConfig = {};
19
+ try {
20
+ var result = explorer.load(rootPath(configFilePath));
21
+ if (
22
+ result &&
23
+ result.config &&
24
+ isObj(result.config)
25
+ ) {
26
+ userBuildConfig = result.config;
27
+ }
28
+ } catch (e) {
29
+ // ignore
30
+ }
31
+ return userBuildConfig;
32
+ }
33
+
34
+ /*
35
+ * 返回静态资源路径(不需要被处理的资源)
36
+ * project/static
37
+ * */
38
+ function assetsPath(_path) {
39
+ return path.posix.join('', _path)
40
+ }
41
+
42
+ function rootPath(..._path) {
43
+ return path.join(process.cwd(), ..._path)
44
+ }
45
+
46
+ // 监听webpack监控以外的文件重启服务
47
+ /**
48
+ * 监听文件或目录变化并重启服务
49
+ * @param {string} pathname - 需要监听的文件或目录路径
50
+ * @param {function} restartService - 重启服务的回调函数
51
+ */
52
+ function getWatchFileRestartService(pathname, restartService) {
53
+ var reStart = typeof restartService === 'function' && restartService || function () { };
54
+ // 获取文件或目录的状态信息
55
+ fs.stat(pathname, (err, stats) => {
56
+ if (!err) {
57
+ // 监听文件或目录的变化事件
58
+ fs.watch(pathname, (eventType, filename) => {
59
+ // 如果是文件,直接重启服务
60
+ if (stats.isFile()) {
61
+ // 如果是文件直接重启服务
62
+ reStart();
63
+ } else if (stats.isDirectory()) {
64
+ // 如果是文件夹,则判断是否删除或者新增
65
+ if (eventType == 'rename') {
66
+ reStart();
67
+ }
68
+ }
69
+ })
70
+ }
71
+ });
72
+ }
73
+
74
+ module.exports = {
75
+ configFilePath,
76
+ getWatchFileRestartService,
77
+ rootPath,
78
+ assetsPath,
79
+ getUserConfig,
80
+ isObj
76
81
  }
@@ -1,81 +1,84 @@
1
- var { spawn, exec, execSync } = require('child_process');
2
- var ora = require('ora');
3
- var path = require('path');
4
- var chalk = require('chalk');
5
- var { utils, processConfig } = require('./options');
6
- var childProcess;
7
-
8
- /**
9
- * 监听目录是否有文件名变动,如果有则重启服务
10
- */
11
- if (Array.isArray(processConfig.watch) && processConfig.watch.length > 0) {
12
- processConfig.watch.forEach(dirname => {
13
- utils.getWatchFileRestartService(utils.rootPath(dirname), () => {
14
- // 监听进程退出事件
15
- childProcess.on('exit', (code, signal) => {
16
- /**
17
- * 重启服务
18
- */
19
- startServer();
20
- });
21
- // 杀掉进程
22
- childProcess.kill('SIGTERM');
23
- })
24
- })
25
- }
26
-
27
-
28
- /**
29
- * 启动服务
30
- */
31
- module.exports = function startServer() {
32
- var spinner = ora('Starting dev server... \n');
33
- spinner.start();
34
- childProcess = spawn(
35
- 'node',
36
- ['--max_old_space_size=4096', path.join(__dirname, './dev-server.js'), ...process.argv.slice(2)],
37
- {
38
- env: Object.assign({}, process.env, {
39
- NODE_ENV: 'development', // 根据需要修改或添加其它环境变量
40
- // EXAMPLE_VAR: 'value'
41
- }),
42
- stdio: 'pipe'
43
- }
44
- );
45
-
46
- // 监听子进程输出
47
- childProcess.stdout.on('data', (data) => {
48
- // 保留原有输出
49
- console.group(`${data}`);
50
- console.groupEnd();
51
- });
52
-
53
- // 从 stderr 解析进度并用 ora 显示
54
- childProcess.stderr.on('data', (data) => {
55
- const str = data.toString();
56
- // 匹配百分比,如 "45%" "100%"
57
- const m = str.match(/(\d{1,3})%/);
58
- if (m) {
59
- const pct = m[1];
60
- spinner.text = `Building ${chalk.green.bold(pct + '%')} `;
61
- if (pct === '100' || str.includes('100%')) {
62
- spinner.succeed(chalk.green.bold('Build 100%'));
63
- if (spinner.isSpinning) spinner.stop();
64
- }
65
- return;
66
- }
67
- if (str.includes('100%')) {
68
- spinner.succeed(chalk.green.bold('Build 100%'));
69
- if (spinner.isSpinning) spinner.stop();
70
- }
71
- // 捕获错误等信息并显示
72
- if (/error/i.test(str) && !str.includes('SassError')) {
73
- spinner.fail(str.split(/\r?\n/)[0]);
74
- }
75
- });
76
-
77
- childProcess.on('close', (exitCode) => {
78
- if (spinner.isSpinning) spinner.stop();
79
- console.log(`======= Service Closed (code: ${exitCode}) ======`);
80
- });
81
- }
1
+ var { spawn, exec, execSync } = require('child_process');
2
+ var ora = require('ora');
3
+ var path = require('path');
4
+ var chalk = require('chalk');
5
+ var { utils, processConfig } = require('./options');
6
+ var childProcess;
7
+
8
+ /**
9
+ * 监听目录是否有文件名变动,如果有则重启服务
10
+ */
11
+ var watchFiles = [
12
+ utils.configFilePath, processConfig.compileDir,
13
+ ...processConfig.watch
14
+ ]
15
+ watchFiles.forEach(dirname => {
16
+ utils.getWatchFileRestartService(utils.rootPath(dirname), () => {
17
+ // 监听进程退出事件
18
+ childProcess.on('exit', (code, signal) => {
19
+ /**
20
+ * 重启服务
21
+ */
22
+ startServer();
23
+ });
24
+ // 杀掉进程
25
+ childProcess.kill('SIGTERM');
26
+ })
27
+ })
28
+
29
+
30
+
31
+ /**
32
+ * 启动服务
33
+ */
34
+ module.exports = function startServer() {
35
+ var spinner = ora('Starting dev server... \n');
36
+ spinner.start();
37
+ childProcess = spawn(
38
+ 'node',
39
+ ['--max_old_space_size=4096', path.join(__dirname, './dev-server.js'), ...process.argv.slice(2)],
40
+ {
41
+ env: Object.assign({}, process.env, {
42
+ NODE_ENV: 'development', // 根据需要修改或添加其它环境变量
43
+ // EXAMPLE_VAR: 'value'
44
+ }),
45
+ stdio: 'pipe'
46
+ }
47
+ );
48
+
49
+ // 监听子进程输出
50
+ childProcess.stdout.on('data', (data) => {
51
+ // 保留原有输出
52
+ console.group(`${data}`);
53
+ console.groupEnd();
54
+ });
55
+
56
+ // stderr 解析进度并用 ora 显示
57
+ childProcess.stderr.on('data', (data) => {
58
+ const str = data.toString();
59
+ // 匹配百分比,如 "45%" 或 "100%"
60
+ const m = str.match(/(\d{1,3})%/);
61
+ if (m) {
62
+ const pct = m[1];
63
+ spinner.text = `Building ${chalk.green.bold(pct + '%')} `;
64
+ if (pct === '100' || str.includes('100%')) {
65
+ spinner.succeed(chalk.green.bold('Build 100%'));
66
+ if (spinner.isSpinning) spinner.stop();
67
+ }
68
+ return;
69
+ }
70
+ if (str.includes('100%')) {
71
+ spinner.succeed(chalk.green.bold('Build 100%'));
72
+ if (spinner.isSpinning) spinner.stop();
73
+ }
74
+ // 捕获错误等信息并显示
75
+ if (/error/i.test(str) && !str.includes('SassError')) {
76
+ spinner.fail(str.split(/\r?\n/)[0]);
77
+ }
78
+ });
79
+
80
+ childProcess.on('close', (exitCode) => {
81
+ if (spinner.isSpinning) spinner.stop();
82
+ console.log(`======= Service Closed (code: ${exitCode}) ======`);
83
+ });
84
+ }
package/index.js CHANGED
@@ -1,8 +1,8 @@
1
- var startService = require('./conf/webpack-server')
2
- var buildPack = require('./conf/build')
3
- var buildDll = require('./conf/config/webpack.dll.conf.js')
4
- module.exports = {
5
- startService,
6
- buildPack,
7
- buildDll
1
+ var startService = require('./conf/webpack-server')
2
+ var buildPack = require('./conf/build')
3
+ var buildDll = require('./conf/config/webpack.dll.conf.js')
4
+ module.exports = {
5
+ startService,
6
+ buildPack,
7
+ buildDll
8
8
  }
package/package.json CHANGED
@@ -1,116 +1,116 @@
1
- {
2
- "name": "qmzreact",
3
- "version": "1.0.13",
4
- "description": "前端react本地启动服务和打包工具",
5
- "author": {
6
- "name": "qmz",
7
- "email": "1223094862@qq.com"
8
- },
9
- "publisher": "1223094862@qq.com",
10
- "private": false,
11
- "main": "index.js",
12
- "bin": {
13
- "qmzreact": "bin/qmzreact.js"
14
- },
15
- "files": [
16
- "bin",
17
- "conf",
18
- "index.js"
19
- ],
20
- "keywords": [
21
- "react-cli",
22
- "webpack"
23
- ],
24
- "license": "ISC",
25
- "dependencies": {
26
- "@babel/core": "^7.18.2",
27
- "@babel/plugin-proposal-decorators": "^7.18.2",
28
- "@babel/plugin-transform-runtime": "^7.18.2",
29
- "@babel/preset-env": "^7.18.2",
30
- "@babel/preset-flow": "^7.17.12",
31
- "@babel/preset-react": "^7.17.12",
32
- "@babel/preset-typescript": "^7.28.5",
33
- "@babel/register": "^7.17.7",
34
- "@babel/runtime-corejs3": "^7.18.0",
35
- "@types/css-modules": "^1.0.5",
36
- "@types/hoist-non-react-statics": "^3.3.1",
37
- "@types/react": "^17.0.2",
38
- "@types/react-dom": "^17.0.2",
39
- "@types/react-router-dom": "^5.3.3",
40
- "add-asset-html-webpack-plugin": "^5.0.2",
41
- "autoprefixer": "^10.4.7",
42
- "babel-jest": "^28.0.3",
43
- "babel-loader": "^8.2.5",
44
- "babel-plugin-import": "^1.13.3",
45
- "classnames": "^2.3.1",
46
- "connect-history-api-fallback": "^1.6.0",
47
- "core-js": "^3.22.7",
48
- "cross-spawn": "^7.0.3",
49
- "css-loader": " ^6.7.1",
50
- "css-minimizer-webpack-plugin": "~4.0.0",
51
- "eslint": "^8.14.0",
52
- "eslint-plugin-react": "^7.30.1",
53
- "eslint-webpack-plugin": "^3.2.0",
54
- "express": "^4.18.1",
55
- "file-loader": "^6.2.0",
56
- "glob": "^7.2.0",
57
- "html-loader": "^3.1.0",
58
- "html-webpack-plugin": "^5.5.0",
59
- "http-proxy-middleware": "^2.0.6",
60
- "lint-staged": "^12.4.1",
61
- "mini-css-extract-plugin": "~2.6.0",
62
- "open": "^8.4.0",
63
- "ora": "^5.4.1",
64
- "postcss": "^8.4.14",
65
- "postcss-loader": "^7.0.0",
66
- "prettier": "^2.6.2",
67
- "querystring": "^0.2.1",
68
- "rax": "^1.2.2",
69
- "react": "^17.0.2",
70
- "react-dom": "^17.0.2",
71
- "react-router": "^5.2.1",
72
- "react-router-dom": "^5.3.0",
73
- "sass": "^1.52.1",
74
- "sass-loader": "^13.0.2",
75
- "script-loader": "^0.7.2",
76
- "shelljs": "^0.8.5",
77
- "style-loader": "^3.3.1",
78
- "terser-webpack-plugin": "^5.3.1",
79
- "thread-loader": "^4.0.2",
80
- "ts-loader": "^9.5.4",
81
- "url-loader": "^4.1.1",
82
- "webpack": "^5.72.1",
83
- "webpack-bundle-analyzer": "^4.5.0",
84
- "webpack-dev-middleware": "^5.3.3",
85
- "webpack-hot-middleware": "^2.25.1",
86
- "webpack-merge": "^5.8.0",
87
- "yargs-parser": "20.2.4",
88
- "yorkie": "^2.0.0"
89
- },
90
- "devDependencies": {},
91
- "peerDependencies": {
92
- "react": "^17.0.2",
93
- "react-dom": "^17.0.2",
94
- "react-router": "^5.2.1",
95
- "react-router-dom": "^5.3.0",
96
- "webpack": "^5.72.1",
97
- "webpack-bundle-analyzer": "^4.5.0",
98
- "webpack-dev-middleware": "^5.3.3",
99
- "webpack-hot-middleware": "^2.25.1",
100
- "webpack-merge": "^5.8.0",
101
- "sass": "^1.52.1",
102
- "sass-loader": "^13.0.2",
103
- "core-js": "^3.22.7"
104
- },
105
- "scripts": {
106
- "test": "echo \"Error: no test specified\" && exit 1"
107
- },
108
- "repository": {
109
- "type": "git",
110
- "url": "git+https://github.com/qiumzWeb/react-cli.git"
111
- },
112
- "bugs": {
113
- "url": "https://github.com/qiumzWeb/react-cli/issues"
114
- },
115
- "homepage": "https://github.com/qiumzWeb/react-cli#readme"
116
- }
1
+ {
2
+ "name": "qmzreact",
3
+ "version": "1.0.14",
4
+ "description": "前端react本地启动服务和打包工具",
5
+ "author": {
6
+ "name": "qmz",
7
+ "email": "1223094862@qq.com"
8
+ },
9
+ "publisher": "1223094862@qq.com",
10
+ "private": false,
11
+ "main": "index.js",
12
+ "bin": {
13
+ "qmzreact": "bin/qmzreact.js"
14
+ },
15
+ "files": [
16
+ "bin",
17
+ "conf",
18
+ "index.js"
19
+ ],
20
+ "keywords": [
21
+ "react-cli",
22
+ "webpack"
23
+ ],
24
+ "license": "ISC",
25
+ "dependencies": {
26
+ "@babel/core": "^7.18.2",
27
+ "@babel/plugin-proposal-decorators": "^7.18.2",
28
+ "@babel/plugin-transform-runtime": "^7.18.2",
29
+ "@babel/preset-env": "^7.18.2",
30
+ "@babel/preset-flow": "^7.17.12",
31
+ "@babel/preset-react": "^7.17.12",
32
+ "@babel/preset-typescript": "^7.28.5",
33
+ "@babel/register": "^7.17.7",
34
+ "@babel/runtime-corejs3": "^7.18.0",
35
+ "@types/css-modules": "^1.0.5",
36
+ "@types/hoist-non-react-statics": "^3.3.1",
37
+ "@types/react": "^17.0.2",
38
+ "@types/react-dom": "^17.0.2",
39
+ "@types/react-router-dom": "^5.3.3",
40
+ "add-asset-html-webpack-plugin": "^5.0.2",
41
+ "autoprefixer": "^10.4.7",
42
+ "babel-jest": "^28.0.3",
43
+ "babel-loader": "^8.2.5",
44
+ "babel-plugin-import": "^1.13.3",
45
+ "classnames": "^2.3.1",
46
+ "connect-history-api-fallback": "^1.6.0",
47
+ "core-js": "^3.22.7",
48
+ "cross-spawn": "^7.0.3",
49
+ "css-loader": " ^6.7.1",
50
+ "css-minimizer-webpack-plugin": "~4.0.0",
51
+ "eslint": "^8.14.0",
52
+ "eslint-plugin-react": "^7.30.1",
53
+ "eslint-webpack-plugin": "^3.2.0",
54
+ "express": "^4.18.1",
55
+ "file-loader": "^6.2.0",
56
+ "glob": "^7.2.0",
57
+ "html-loader": "^3.1.0",
58
+ "html-webpack-plugin": "^5.5.0",
59
+ "http-proxy-middleware": "^2.0.6",
60
+ "lint-staged": "^12.4.1",
61
+ "mini-css-extract-plugin": "~2.6.0",
62
+ "open": "^8.4.0",
63
+ "ora": "^5.4.1",
64
+ "postcss": "^8.4.14",
65
+ "postcss-loader": "^7.0.0",
66
+ "prettier": "^2.6.2",
67
+ "querystring": "^0.2.1",
68
+ "rax": "^1.2.2",
69
+ "react": "^17.0.2",
70
+ "react-dom": "^17.0.2",
71
+ "react-router": "^5.2.1",
72
+ "react-router-dom": "^5.3.0",
73
+ "sass": "^1.52.1",
74
+ "sass-loader": "^13.0.2",
75
+ "script-loader": "^0.7.2",
76
+ "shelljs": "^0.8.5",
77
+ "style-loader": "^3.3.1",
78
+ "terser-webpack-plugin": "^5.3.1",
79
+ "thread-loader": "^4.0.2",
80
+ "ts-loader": "^9.5.4",
81
+ "url-loader": "^4.1.1",
82
+ "webpack": "^5.72.1",
83
+ "webpack-bundle-analyzer": "^4.5.0",
84
+ "webpack-dev-middleware": "^5.3.3",
85
+ "webpack-hot-middleware": "^2.25.1",
86
+ "webpack-merge": "^5.8.0",
87
+ "yargs-parser": "20.2.4",
88
+ "yorkie": "^2.0.0"
89
+ },
90
+ "devDependencies": {},
91
+ "peerDependencies": {
92
+ "react": "^17.0.2",
93
+ "react-dom": "^17.0.2",
94
+ "react-router": "^5.2.1",
95
+ "react-router-dom": "^5.3.0",
96
+ "webpack": "^5.72.1",
97
+ "webpack-bundle-analyzer": "^4.5.0",
98
+ "webpack-dev-middleware": "^5.3.3",
99
+ "webpack-hot-middleware": "^2.25.1",
100
+ "webpack-merge": "^5.8.0",
101
+ "sass": "^1.52.1",
102
+ "sass-loader": "^13.0.2",
103
+ "core-js": "^3.22.7"
104
+ },
105
+ "scripts": {
106
+ "test": "echo \"Error: no test specified\" && exit 1"
107
+ },
108
+ "repository": {
109
+ "type": "git",
110
+ "url": "git+https://github.com/qiumzWeb/react-cli.git"
111
+ },
112
+ "bugs": {
113
+ "url": "https://github.com/qiumzWeb/react-cli/issues"
114
+ },
115
+ "homepage": "https://github.com/qiumzWeb/react-cli#readme"
116
+ }