qmzreact 1.0.15 → 1.0.17
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/config/loaders.js +3 -10
- package/conf/config/webpack.base.conf.js +11 -1
- package/conf/config/webpack.dll.conf.js +2 -1
- package/conf/dev-server.js +11 -3
- package/conf/utils.js +24 -2
- package/conf/webpack-server.js +6 -3
- package/package.json +1 -1
package/conf/config/loaders.js
CHANGED
|
@@ -8,12 +8,6 @@ var sassGlobalStyles = '';
|
|
|
8
8
|
processConfig.sassGlobalStyles.forEach((item) => {
|
|
9
9
|
return sassGlobalStyles += `@import "${item}";`;
|
|
10
10
|
});
|
|
11
|
-
try {
|
|
12
|
-
fs.accessSync(utils.rootPath('src/global.scss'), fs.constants.F_OK);
|
|
13
|
-
sassGlobalStyles += `@import "@/global.scss";`;
|
|
14
|
-
} catch (err) {
|
|
15
|
-
// console.log(err);
|
|
16
|
-
};
|
|
17
11
|
module.exports = [
|
|
18
12
|
{
|
|
19
13
|
test: /\.t|jsx?$/,
|
|
@@ -126,14 +120,13 @@ module.exports = [
|
|
|
126
120
|
// 3. 自定义函数:遇到 node_modules 就“放行”,否则“使用上面的规则”
|
|
127
121
|
getLocalIdent: (context, localIdentName, localName, options) => {
|
|
128
122
|
// 如果是 node_modules 里的文件
|
|
129
|
-
if (context.resourcePath
|
|
123
|
+
if (/\.module\.(sa|sc|c)ss$/i.test(context.resourcePath)) {
|
|
130
124
|
// 直接返回原始类名(相当于变相的 global 模式)
|
|
131
|
-
return
|
|
125
|
+
return null;
|
|
132
126
|
}
|
|
133
|
-
|
|
134
127
|
// 如果是自己 src 里的文件
|
|
135
128
|
// 返回 null,告诉 css-loader:“请用 localIdentName 的规则去生成哈希”
|
|
136
|
-
return
|
|
129
|
+
return localName;
|
|
137
130
|
}
|
|
138
131
|
}
|
|
139
132
|
}, processConfig.cssLoaderOptions)
|
|
@@ -9,13 +9,20 @@ var AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin');
|
|
|
9
9
|
var fs = require('fs');
|
|
10
10
|
|
|
11
11
|
var entry = [];
|
|
12
|
+
try {
|
|
13
|
+
var globalPath = utils.rootPath('src/global.scss');
|
|
14
|
+
fs.accessSync(globalPath, fs.constants.F_OK);
|
|
15
|
+
entry.push(globalPath);
|
|
16
|
+
} catch (err) {
|
|
17
|
+
// console.log(err);
|
|
18
|
+
};
|
|
12
19
|
var entryFile = ['index.js', 'index.jsx', 'index.ts', 'index.tsx'];
|
|
13
20
|
for (var i = 0; i < entryFile.length; i++) {
|
|
14
21
|
var entryPath = utils.rootPath(processConfig.compileDir, entryFile[i]);
|
|
15
22
|
try {
|
|
16
23
|
const stats = fs.statSync(entryPath);
|
|
17
24
|
if (stats.isFile()) {
|
|
18
|
-
entry
|
|
25
|
+
entry.push(entryPath);
|
|
19
26
|
}
|
|
20
27
|
break;
|
|
21
28
|
} catch (err) {
|
|
@@ -23,6 +30,7 @@ for (var i = 0; i < entryFile.length; i++) {
|
|
|
23
30
|
}
|
|
24
31
|
}
|
|
25
32
|
|
|
33
|
+
|
|
26
34
|
var plugins = [];
|
|
27
35
|
if (processConfig.dll) {
|
|
28
36
|
plugins = [
|
|
@@ -38,6 +46,8 @@ if (processConfig.dll) {
|
|
|
38
46
|
})
|
|
39
47
|
]
|
|
40
48
|
}
|
|
49
|
+
|
|
50
|
+
|
|
41
51
|
module.exports = {
|
|
42
52
|
entry: [
|
|
43
53
|
...processConfig.entry,
|
package/conf/dev-server.js
CHANGED
|
@@ -25,14 +25,18 @@ var hotMiddleware = require('webpack-hot-middleware')(compiler)
|
|
|
25
25
|
// // force page reload when html-webpack-plugin template changes
|
|
26
26
|
compiler.hooks.make.tap('compilation', function (compilation) {
|
|
27
27
|
compilation.hooks.finishModules.tap('html-webpack-plugin-after-emit', function (modules) {
|
|
28
|
+
process.env.NODE_STATUS = "running";
|
|
28
29
|
hotMiddleware.publish({ action: 'reload' })
|
|
29
30
|
})
|
|
30
31
|
})
|
|
31
32
|
// print compiler finished info
|
|
32
33
|
compiler.hooks.done.tap('AfterCompiler', function(stats) {
|
|
33
34
|
setTimeout(() => {
|
|
35
|
+
if (process.env.NODE_STATUS === 'rebuild') {
|
|
36
|
+
hotMiddleware.publish({ action: 'reload' })
|
|
37
|
+
}
|
|
34
38
|
console.log('webpack \x1b[1mcompiled \x1B[32mfinished \x1B[37min',new Date().toLocaleString(),'\x1b[0m')
|
|
35
|
-
},
|
|
39
|
+
}, 2000)
|
|
36
40
|
})
|
|
37
41
|
|
|
38
42
|
|
|
@@ -79,7 +83,9 @@ if (processConfig.isHttps) {
|
|
|
79
83
|
}
|
|
80
84
|
var uri = 'https://localhost:' + port // 直接显示页面
|
|
81
85
|
console.log('Listening at ' + uri + '\n')
|
|
82
|
-
|
|
86
|
+
if (process.env.NODE_STATUS === 'build') {
|
|
87
|
+
opn(uri)
|
|
88
|
+
}
|
|
83
89
|
})
|
|
84
90
|
} else {
|
|
85
91
|
service = app.listen(port, function (err) {
|
|
@@ -89,7 +95,9 @@ if (processConfig.isHttps) {
|
|
|
89
95
|
}
|
|
90
96
|
var uri = 'http://localhost:' + port // 直接显示页面
|
|
91
97
|
console.log('Listening at ' + uri + '\n')
|
|
92
|
-
|
|
98
|
+
if (process.env.NODE_STATUS === 'build') {
|
|
99
|
+
opn(uri)
|
|
100
|
+
}
|
|
93
101
|
|
|
94
102
|
})
|
|
95
103
|
}
|
package/conf/utils.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
var path = require('path')
|
|
2
2
|
var fs = require('fs')
|
|
3
|
+
var crypto = require('crypto')
|
|
3
4
|
var { cosmiconfigSync } = require('cosmiconfig');
|
|
4
5
|
|
|
5
6
|
var configFilePath = 'build.config.js';
|
|
@@ -58,8 +59,29 @@ function getWatchFileRestartService(pathname, restartService) {
|
|
|
58
59
|
fs.watch(pathname, (eventType, filename) => {
|
|
59
60
|
// 如果是文件,直接重启服务
|
|
60
61
|
if (stats.isFile()) {
|
|
61
|
-
|
|
62
|
-
|
|
62
|
+
// 只在文件内容实际修改(mtime 变化)时重启
|
|
63
|
+
fs.stat(pathname, (err2, newStats) => {
|
|
64
|
+
if (err2) return;
|
|
65
|
+
if (eventType == 'rename') {
|
|
66
|
+
reStart();
|
|
67
|
+
}
|
|
68
|
+
if (eventType == 'change') {
|
|
69
|
+
fs.readFile(pathname, (err2, data) => {
|
|
70
|
+
if (err2) return;
|
|
71
|
+
// 计算内容哈希,首次读取时保存哈希,之后比较
|
|
72
|
+
var hash = crypto.createHash('sha256').update(data).digest('hex');
|
|
73
|
+
if (!stats._contentHash) {
|
|
74
|
+
stats._contentHash = hash;
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
// 内容未变则不重启
|
|
78
|
+
if (stats._contentHash === hash) return;
|
|
79
|
+
// 更新保存的状态与哈希,避免重复触发
|
|
80
|
+
stats._contentHash = hash;
|
|
81
|
+
reStart();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
});
|
|
63
85
|
} else if (stats.isDirectory()) {
|
|
64
86
|
// 如果是文件夹,则判断是否删除或者新增
|
|
65
87
|
if (eventType == 'rename') {
|
package/conf/webpack-server.js
CHANGED
|
@@ -19,7 +19,7 @@ watchFiles.forEach(dirname => {
|
|
|
19
19
|
/**
|
|
20
20
|
* 重启服务
|
|
21
21
|
*/
|
|
22
|
-
startServer();
|
|
22
|
+
startServer('rebuild');
|
|
23
23
|
});
|
|
24
24
|
// 杀掉进程
|
|
25
25
|
childProcess.kill('SIGTERM');
|
|
@@ -31,7 +31,7 @@ watchFiles.forEach(dirname => {
|
|
|
31
31
|
/**
|
|
32
32
|
* 启动服务
|
|
33
33
|
*/
|
|
34
|
-
|
|
34
|
+
function startServer(status) {
|
|
35
35
|
var spinner = ora('Starting dev server... \n');
|
|
36
36
|
spinner.start();
|
|
37
37
|
childProcess = spawn(
|
|
@@ -40,7 +40,7 @@ module.exports = function startServer() {
|
|
|
40
40
|
{
|
|
41
41
|
env: Object.assign({}, process.env, {
|
|
42
42
|
NODE_ENV: 'development', // 根据需要修改或添加其它环境变量
|
|
43
|
-
|
|
43
|
+
NODE_STATUS: status || 'build'
|
|
44
44
|
}),
|
|
45
45
|
stdio: 'pipe'
|
|
46
46
|
}
|
|
@@ -82,3 +82,6 @@ module.exports = function startServer() {
|
|
|
82
82
|
console.log(`======= Service Closed (code: ${exitCode}) ======`);
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
module.exports = startServer
|