hw-weapp-compiler 1.0.16 → 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/build/dev.js +6 -7
- package/build/utils/cleanDistForDev.js +29 -0
- package/package.json +1 -1
package/build/dev.js
CHANGED
|
@@ -2,20 +2,19 @@ const webpack = require('webpack');
|
|
|
2
2
|
const { ENV } = require('./config/constants');
|
|
3
3
|
const webpackConfig = require('./webpack.config');
|
|
4
4
|
const { createCompilerHandler } = require('./utils/createCompilerHandler');
|
|
5
|
+
const { cleanDistForDev } = require('./utils/cleanDistForDev');
|
|
5
6
|
|
|
6
7
|
module.exports = async (opts) => {
|
|
7
|
-
//
|
|
8
|
-
//
|
|
8
|
+
// watch 增量重建不使用 output.clean:app.json / 页面 .json/.wxml 由 js-loader 副作用 emit,
|
|
9
|
+
// 热更新时若入口 JS 未重跑,output.clean 会先删 dist 导致这些文件丢失。
|
|
10
|
+
// 启动时单独清理一次旧产物,保留 weapp.env.json 等启动前写入的文件。
|
|
11
|
+
await cleanDistForDev();
|
|
12
|
+
|
|
9
13
|
const compiler = webpack(
|
|
10
14
|
await webpackConfig(
|
|
11
15
|
{
|
|
12
16
|
mode: ENV.DEV,
|
|
13
17
|
devtool: 'cheap-module-source-map',
|
|
14
|
-
output: {
|
|
15
|
-
clean: {
|
|
16
|
-
keep: /^(project\.config\.json|weapp\.env\.json)$/,
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
18
|
},
|
|
20
19
|
opts || {},
|
|
21
20
|
),
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const fse = require('fs-extra');
|
|
3
|
+
const { DIST_DIR } = require('../config/constants');
|
|
4
|
+
|
|
5
|
+
const KEEP_FILES = new Set(['project.config.json', 'weapp.env.json']);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 开发模式启动时清理 dist 旧产物。
|
|
9
|
+
* watch 增量重建不再使用 output.clean,避免副作用 emit 的 json/wxml 被清掉后未重生成。
|
|
10
|
+
*/
|
|
11
|
+
async function cleanDistForDev() {
|
|
12
|
+
if (!(await fse.pathExists(DIST_DIR))) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const entries = await fse.readdir(DIST_DIR);
|
|
17
|
+
await Promise.all(
|
|
18
|
+
entries.map(async (entry) => {
|
|
19
|
+
if (KEEP_FILES.has(entry)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
await fse.remove(path.join(DIST_DIR, entry));
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
cleanDistForDev,
|
|
29
|
+
};
|