hw-weapp-compiler 1.0.11 → 1.0.13

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.
@@ -10,7 +10,6 @@ const { getEntries } = require('../config/getEntries');
10
10
  const { loadModule } = require('../utils/loadModule');
11
11
 
12
12
  module.exports = async function loader(source) {
13
- this.cacheable(true);
14
13
  const filePath = this.resourcePath;
15
14
  const fileInfo = path.parse(filePath);
16
15
  const sourceStr = source.toString();
@@ -18,8 +17,14 @@ module.exports = async function loader(source) {
18
17
  const imports = [sourceStr];
19
18
 
20
19
  const entries = await getEntries();
20
+ const entryPath = path.resolve(fileInfo.dir, fileInfo.name);
21
+ const isEntryFile = Object.values(entries).indexOf(entryPath) !== -1;
21
22
 
22
- if (Object.values(entries).indexOf(path.resolve(fileInfo.dir, fileInfo.name)) !== -1) {
23
+ // 入口 JS 会通过 loadModule 产出同名 json/wxml。若入口模块命中持久化缓存,
24
+ // dev 二次启动时 output.clean 删除后的 app.json 不会重新 emit。
25
+ this.cacheable(!isEntryFile);
26
+
27
+ if (isEntryFile) {
23
28
  const exts = ['.less', '.wxss', '.css', '.json', '.wxml'];
24
29
  const checks = await Promise.all(
25
30
  exts.map(async (ext) => {
@@ -24,7 +24,7 @@ function collectStaticRequires(content) {
24
24
  let ast;
25
25
  let parseError = null;
26
26
  try {
27
- ast = acorn.parse(content, { ecmaVersion: 'latest', sourceType: 'script' });
27
+ ast = acorn.parse(content, { ecmaVersion: '2020', sourceType: 'script' });
28
28
  } catch (error) {
29
29
  parseError = error;
30
30
  return { requires, parseError };
@@ -138,7 +138,7 @@ function injectSubpackageRequires(content, assetName, subpackages) {
138
138
  const res = subpackages[subpackage];
139
139
 
140
140
  if (
141
- assetName.startsWith(subpackage) &&
141
+ (assetName === subpackage || assetName.startsWith(`${subpackage}/`)) &&
142
142
  !/(subpackage_common\.(js|wxss))$/.test(assetName)
143
143
  ) {
144
144
  if (
@@ -312,7 +312,6 @@ module.exports = async (options, { analyzer, quiet } = {}) => {
312
312
  {
313
313
  loader: require.resolve('swc-loader'),
314
314
  options: {
315
- cacheDirectory: true,
316
315
  // 用 env 模式按 chrome 53 降级,等价原 babel preset-env targets.chrome53。
317
316
  // 关闭 externalHelpers:helper 内联进每个使用文件,不 require("@swc/helpers"),
318
317
  // 也不产 regeneratorRuntime(chrome 53 原生支持 function*)。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hw-weapp-compiler",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "description": "基于 webpack5 的小程序构建工具,兼容 Node.js 14~24",
5
5
  "main": "index.js",
6
6
  "bin": {