hw-weapp-compiler 1.0.4 → 1.0.6
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/loader/js-loader.js +1 -2
- package/build/loader/wxml-loader.js +1 -2
- package/build/loader/wxs-loader.js +1 -2
- package/build/plugin/index.js +1 -1
- package/build/utils/createCompilerHandler.js +15 -1
- package/build/utils/getWxmlAssets.js +9 -3
- package/build/utils/loadModule.js +50 -11
- package/build/webpack.config.js +1 -1
- package/package.json +1 -1
|
@@ -13,7 +13,6 @@ const entries = getEntries();
|
|
|
13
13
|
|
|
14
14
|
module.exports = async function loader(source) {
|
|
15
15
|
this.cacheable(true);
|
|
16
|
-
const callback = this.async();
|
|
17
16
|
const filePath = this.resourcePath;
|
|
18
17
|
const fileInfo = path.parse(filePath);
|
|
19
18
|
const sourceStr = source.toString();
|
|
@@ -46,7 +45,7 @@ module.exports = async function loader(source) {
|
|
|
46
45
|
});
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
return imports.join('');
|
|
50
49
|
};
|
|
51
50
|
|
|
52
51
|
module.exports.raw = true;
|
|
@@ -9,7 +9,6 @@ const { loadModule } = require('../utils/loadModule');
|
|
|
9
9
|
|
|
10
10
|
module.exports = async function loader(source) {
|
|
11
11
|
this.cacheable(true);
|
|
12
|
-
const callback = this.async();
|
|
13
12
|
const filePath = this.resourcePath;
|
|
14
13
|
let content = source.toString();
|
|
15
14
|
const {
|
|
@@ -46,6 +45,6 @@ module.exports = async function loader(source) {
|
|
|
46
45
|
// wxml文件 - 并行 loadModule
|
|
47
46
|
await Promise.all(wxmls.map(([, file]) => loadModule.call(this, file)));
|
|
48
47
|
|
|
49
|
-
|
|
48
|
+
return content;
|
|
50
49
|
};
|
|
51
50
|
module.exports.raw = true;
|
|
@@ -9,7 +9,6 @@ const { loadModule } = require('../utils/loadModule');
|
|
|
9
9
|
|
|
10
10
|
module.exports = async function loader(source) {
|
|
11
11
|
this.cacheable(true);
|
|
12
|
-
const callback = this.async();
|
|
13
12
|
const filePath = this.resourcePath;
|
|
14
13
|
const content = source.toString();
|
|
15
14
|
const fileInfo = path.parse(filePath);
|
|
@@ -26,6 +25,6 @@ module.exports = async function loader(source) {
|
|
|
26
25
|
}),
|
|
27
26
|
);
|
|
28
27
|
|
|
29
|
-
|
|
28
|
+
return content;
|
|
30
29
|
};
|
|
31
30
|
module.exports.raw = true;
|
package/build/plugin/index.js
CHANGED
|
@@ -7,17 +7,31 @@ const chalk = require('chalk');
|
|
|
7
7
|
function createCompilerHandler(label) {
|
|
8
8
|
return (err, stats) => {
|
|
9
9
|
if (err) {
|
|
10
|
+
console.error(chalk.red(`${label} failed with fatal error:`));
|
|
10
11
|
console.error(err);
|
|
11
12
|
return;
|
|
12
13
|
}
|
|
13
14
|
|
|
14
15
|
if (stats.hasErrors()) {
|
|
15
|
-
console.
|
|
16
|
+
console.error(
|
|
16
17
|
stats.toString({
|
|
17
18
|
chunks: false,
|
|
18
19
|
colors: true,
|
|
19
20
|
}),
|
|
20
21
|
);
|
|
22
|
+
console.error(chalk.red(`${label} completed with errors`));
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (stats.hasWarnings()) {
|
|
27
|
+
console.warn(
|
|
28
|
+
stats.toString({
|
|
29
|
+
chunks: false,
|
|
30
|
+
colors: true,
|
|
31
|
+
warnings: true,
|
|
32
|
+
errors: false,
|
|
33
|
+
}),
|
|
34
|
+
);
|
|
21
35
|
}
|
|
22
36
|
|
|
23
37
|
console.log(chalk.green(`${label} completed in ${(stats.endTime - stats.startTime) / 1000} seconds`));
|
|
@@ -1,12 +1,17 @@
|
|
|
1
|
+
const { createPool, POOL_SIZE } = require('./loadModule');
|
|
1
2
|
const htmlparser2 = require('htmlparser2');
|
|
2
3
|
const path = require('path');
|
|
3
4
|
const fse = require('fs-extra');
|
|
4
5
|
const { ASSET_EXT_PATTERN, PATTERNS, SRC_DIR } = require('../config/constants');
|
|
5
6
|
|
|
7
|
+
const resolvePool = createPool(POOL_SIZE);
|
|
8
|
+
|
|
6
9
|
function getWxmlAssets(filePath, content) {
|
|
7
10
|
const resolvePath = (attr, dir) => {
|
|
8
|
-
return
|
|
9
|
-
|
|
11
|
+
return resolvePool(
|
|
12
|
+
() =>
|
|
13
|
+
new Promise((resolve) => {
|
|
14
|
+
this.resolve(SRC_DIR, attr, async (err, result) => {
|
|
10
15
|
let res = result;
|
|
11
16
|
if (err) {
|
|
12
17
|
if (await fse.pathExists(path.resolve(dir, attr))) {
|
|
@@ -20,7 +25,8 @@ function getWxmlAssets(filePath, content) {
|
|
|
20
25
|
resolve(res);
|
|
21
26
|
}
|
|
22
27
|
});
|
|
23
|
-
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
24
30
|
};
|
|
25
31
|
return new Promise((resolve, reject) => {
|
|
26
32
|
let allAttrs = [];
|
|
@@ -1,16 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
const POOL_SIZE = 16;
|
|
2
|
+
|
|
3
|
+
function createPool(limit) {
|
|
4
|
+
let active = 0;
|
|
5
|
+
const pending = [];
|
|
6
|
+
const next = () => {
|
|
7
|
+
while (pending.length && active < limit) {
|
|
8
|
+
const { fn, resolve, reject } = pending.shift();
|
|
9
|
+
active++;
|
|
10
|
+
Promise.resolve()
|
|
11
|
+
.then(fn)
|
|
12
|
+
.then(
|
|
13
|
+
(v) => {
|
|
14
|
+
active--;
|
|
15
|
+
resolve(v);
|
|
16
|
+
next();
|
|
17
|
+
},
|
|
18
|
+
(e) => {
|
|
19
|
+
active--;
|
|
20
|
+
reject(e);
|
|
21
|
+
next();
|
|
22
|
+
},
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
return (fn) =>
|
|
27
|
+
new Promise((resolve, reject) => {
|
|
28
|
+
pending.push({ fn, resolve, reject });
|
|
29
|
+
next();
|
|
11
30
|
});
|
|
12
|
-
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const pool = createPool(POOL_SIZE);
|
|
34
|
+
|
|
35
|
+
function loadModule(file) {
|
|
36
|
+
return pool(
|
|
37
|
+
() =>
|
|
38
|
+
new Promise((resolve) => {
|
|
39
|
+
this.addDependency(file);
|
|
40
|
+
this.loadModule(file, (err, src) => {
|
|
41
|
+
if (err) {
|
|
42
|
+
this.emitError(err);
|
|
43
|
+
resolve(null);
|
|
44
|
+
} else {
|
|
45
|
+
resolve(src);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}),
|
|
49
|
+
);
|
|
13
50
|
}
|
|
14
51
|
module.exports = {
|
|
15
52
|
loadModule,
|
|
53
|
+
createPool,
|
|
54
|
+
POOL_SIZE,
|
|
16
55
|
};
|
package/build/webpack.config.js
CHANGED
|
@@ -309,6 +309,7 @@ module.exports = (options, { analyzer, quiet } = {}) => {
|
|
|
309
309
|
loader: 'babel-loader',
|
|
310
310
|
options: {
|
|
311
311
|
cacheDirectory: true,
|
|
312
|
+
cacheCompression: false,
|
|
312
313
|
presets: [
|
|
313
314
|
[
|
|
314
315
|
'@babel/preset-env',
|
|
@@ -338,7 +339,6 @@ module.exports = (options, { analyzer, quiet } = {}) => {
|
|
|
338
339
|
cacheGroups,
|
|
339
340
|
},
|
|
340
341
|
},
|
|
341
|
-
cache: false,
|
|
342
342
|
},
|
|
343
343
|
options,
|
|
344
344
|
);
|