qmzreact 1.0.3 → 1.0.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.
- package/README.md +91 -91
- package/bin/qmzreact.js +29 -29
- package/conf/build.js +31 -31
- package/conf/config/chunks.js +33 -33
- package/conf/config/index.js +56 -56
- package/conf/config/loaders.js +156 -155
- package/conf/config/webpack.base.conf.js +63 -63
- package/conf/config/webpack.dev.conf.js +32 -32
- package/conf/config/webpack.dll.conf.js +46 -46
- package/conf/config/webpack.prod.conf.js +76 -76
- package/conf/dev-client.js +6 -6
- package/conf/dev-server.js +97 -97
- package/conf/options.js +45 -45
- package/conf/server.cert +21 -21
- package/conf/server.key +28 -28
- package/conf/utils.js +75 -75
- package/conf/webpack-server.js +81 -81
- package/index.js +7 -7
- package/package.json +67 -1
package/conf/utils.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
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
|
+
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
|
|
76
76
|
}
|
package/conf/webpack-server.js
CHANGED
|
@@ -1,81 +1,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
|
-
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)) {
|
|
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
|
+
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
|
+
}
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qmzreact",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "前端react本地启动服务和打包工具",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "qmz",
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"@babel/preset-env": "^7.18.2",
|
|
30
30
|
"@babel/preset-flow": "^7.17.12",
|
|
31
31
|
"@babel/preset-react": "^7.17.12",
|
|
32
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
32
33
|
"@babel/register": "^7.17.7",
|
|
33
34
|
"@babel/runtime-corejs3": "^7.18.0",
|
|
34
35
|
"@types/css-modules": "^1.0.5",
|
|
@@ -87,6 +88,71 @@
|
|
|
87
88
|
"yorkie": "^2.0.0"
|
|
88
89
|
},
|
|
89
90
|
"devDependencies": {},
|
|
91
|
+
"peerDependencies": {
|
|
92
|
+
"@babel/core": "^7.18.2",
|
|
93
|
+
"@babel/plugin-proposal-decorators": "^7.18.2",
|
|
94
|
+
"@babel/plugin-transform-runtime": "^7.18.2",
|
|
95
|
+
"@babel/preset-env": "^7.18.2",
|
|
96
|
+
"@babel/preset-flow": "^7.17.12",
|
|
97
|
+
"@babel/preset-react": "^7.17.12",
|
|
98
|
+
"@babel/preset-typescript": "^7.28.5",
|
|
99
|
+
"@babel/register": "^7.17.7",
|
|
100
|
+
"@babel/runtime-corejs3": "^7.18.0",
|
|
101
|
+
"@types/css-modules": "^1.0.5",
|
|
102
|
+
"@types/hoist-non-react-statics": "^3.3.1",
|
|
103
|
+
"@types/react": "^17.0.2",
|
|
104
|
+
"@types/react-dom": "^17.0.2",
|
|
105
|
+
"@types/react-router-dom": "^5.3.3",
|
|
106
|
+
"add-asset-html-webpack-plugin": "^5.0.2",
|
|
107
|
+
"autoprefixer": "^10.4.7",
|
|
108
|
+
"babel-jest": "^28.0.3",
|
|
109
|
+
"babel-loader": "^8.2.5",
|
|
110
|
+
"babel-plugin-import": "^1.13.3",
|
|
111
|
+
"classnames": "^2.3.1",
|
|
112
|
+
"connect-history-api-fallback": "^1.6.0",
|
|
113
|
+
"core-js": "~3.22.7",
|
|
114
|
+
"cross-spawn": "^7.0.3",
|
|
115
|
+
"css-loader": " ^6.7.1",
|
|
116
|
+
"css-minimizer-webpack-plugin": "~4.0.0",
|
|
117
|
+
"eslint": "^8.14.0",
|
|
118
|
+
"eslint-plugin-react": "^7.30.1",
|
|
119
|
+
"eslint-webpack-plugin": "^3.2.0",
|
|
120
|
+
"express": "^4.18.1",
|
|
121
|
+
"file-loader": "^6.2.0",
|
|
122
|
+
"glob": "^7.2.0",
|
|
123
|
+
"html-loader": "^3.1.0",
|
|
124
|
+
"html-webpack-plugin": "^5.5.0",
|
|
125
|
+
"http-proxy-middleware": "^2.0.6",
|
|
126
|
+
"lint-staged": "^12.4.1",
|
|
127
|
+
"mini-css-extract-plugin": "~2.6.0",
|
|
128
|
+
"open": "^8.4.0",
|
|
129
|
+
"ora": "^5.4.1",
|
|
130
|
+
"postcss": "^8.4.14",
|
|
131
|
+
"postcss-loader": "^7.0.0",
|
|
132
|
+
"prettier": "^2.6.2",
|
|
133
|
+
"querystring": "^0.2.1",
|
|
134
|
+
"rax": "^1.2.2",
|
|
135
|
+
"react": "^17.0.2",
|
|
136
|
+
"react-dom": "^17.0.2",
|
|
137
|
+
"react-router": "^5.2.1",
|
|
138
|
+
"react-router-dom": "^5.3.0",
|
|
139
|
+
"sass": "~1.52.1",
|
|
140
|
+
"sass-loader": "~13.0.2",
|
|
141
|
+
"script-loader": "^0.7.2",
|
|
142
|
+
"shelljs": "^0.8.5",
|
|
143
|
+
"style-loader": "^3.3.1",
|
|
144
|
+
"terser-webpack-plugin": "^5.3.1",
|
|
145
|
+
"thread-loader": "^4.0.2",
|
|
146
|
+
"ts-loader": "^9.5.4",
|
|
147
|
+
"url-loader": "^4.1.1",
|
|
148
|
+
"webpack": "^5.72.1",
|
|
149
|
+
"webpack-bundle-analyzer": "^4.5.0",
|
|
150
|
+
"webpack-dev-middleware": "^5.3.3",
|
|
151
|
+
"webpack-hot-middleware": "^2.25.1",
|
|
152
|
+
"webpack-merge": "^5.8.0",
|
|
153
|
+
"yargs-parser": "20.2.4",
|
|
154
|
+
"yorkie": "^2.0.0"
|
|
155
|
+
},
|
|
90
156
|
"scripts": {
|
|
91
157
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
92
158
|
},
|