hw-weapp-compiler 1.0.10 → 1.0.12

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.
@@ -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 (
@@ -24,10 +24,6 @@ module.exports = async (options, { analyzer, quiet } = {}) => {
24
24
  const appConfig = getAppConfig();
25
25
  const { alias = {}, publicPath = 'auto', copyFiles = [] } = getConfig();
26
26
 
27
- // swc externalHelpers 产物里有 require("@swc/helpers/..."),本包作为编译器被 npm 安装到
28
- // 用户项目时,@swc/helpers 通常落在本包内层 node_modules 而非用户项目顶层,用户源码
29
- // 所在目录向上解析不到 → 构建直接 Module not found。固定指到本包内的绝对路径。
30
- alias['@swc/helpers'] = path.dirname(require.resolve('@swc/helpers/package.json'));
31
27
  const entries = await getEntries();
32
28
 
33
29
  const assetsName = (resourcePath) => {
@@ -316,16 +312,17 @@ module.exports = async (options, { analyzer, quiet } = {}) => {
316
312
  {
317
313
  loader: require.resolve('swc-loader'),
318
314
  options: {
319
- cacheDirectory: true,
320
315
  // 用 env 模式按 chrome 53 降级,等价原 babel preset-env targets.chrome53。
321
- // swc 不再产出 regeneratorRuntime,而是 require("@swc/helpers/...") 配原生生
322
- // 成器(chrome 53 原生支持 function*),由上方 resolve.alias 固定解析到本包内。
316
+ // 关闭 externalHelpers:helper 内联进每个使用文件,不 require("@swc/helpers")
317
+ // 也不产 regeneratorRuntime(chrome 53 原生支持 function*)。
318
+ // 绝不能开 externalHelpers —— @swc/helpers 是 ESM 形态 `export { ... as _ }`,
319
+ // 经 webpack 转 CJS 后小程序 appservice 模块加载器对 exports key `_` 用
320
+ // Object.defineProperty 且不可重定义,会抛 `Cannot redefine property: _`。
323
321
  env: {
324
322
  targets: { chrome: '53' },
325
323
  },
326
324
  jsc: {
327
325
  parser: { syntax: 'ecmascript' },
328
- externalHelpers: true,
329
326
  },
330
327
  module: { type: 'commonjs' },
331
328
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hw-weapp-compiler",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "基于 webpack5 的小程序构建工具,兼容 Node.js 14~24",
5
5
  "main": "index.js",
6
6
  "bin": {