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.
@@ -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
- callback(null, imports.join(''));
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
- callback(null, content);
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
- callback(null, content);
28
+ return content;
30
29
  };
31
30
  module.exports.raw = true;
@@ -222,7 +222,7 @@ class WeappPlugin {
222
222
  },
223
223
  );
224
224
 
225
- compilation.hooks.processAssets.tap(
225
+ compilation.hooks.processAssets.tapPromise(
226
226
  {
227
227
  name: pluginName,
228
228
  stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
@@ -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.log(
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 new Promise((resolve) => {
9
- this.resolve(SRC_DIR, attr, async (err, result) => {
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
- function loadModule(file) {
2
- return new Promise((resolve) => {
3
- this.addDependency(file);
4
- this.loadModule(file, (err, src) => {
5
- if (err) {
6
- this.emitError(err);
7
- resolve(null);
8
- } else {
9
- resolve(src);
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
  };
@@ -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
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hw-weapp-compiler",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "基于 webpack5 的小程序构建工具,兼容 Node.js 14~24",
5
5
  "main": "index.js",
6
6
  "bin": {