hw-weapp-compiler 1.0.15 → 1.0.16

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.
@@ -1,14 +1,52 @@
1
+ const { compatiblePath } = require('./compatiblePath');
2
+
1
3
  const nodeModulesUsingComponent = [];
4
+ const nodeModulesUsingComponentDirs = [];
2
5
 
3
- function isNodeModulesUsingComponent(name) {
4
- const key = name.replace(/\.(js|wxml|wxss|json|wxs)$/g, '');
6
+ function normalizeComponentKey(name) {
7
+ const key = compatiblePath(name).replace(/\.(js|wxml|wxss|json|wxs|less|css)$/gi, '');
5
8
  const nmIndex = key.indexOf('node_modules/');
6
- const searchKey = nmIndex !== -1 ? key.substring(nmIndex + 'node_modules/'.length) : key;
7
- return nodeModulesUsingComponent.indexOf(searchKey) !== -1;
9
+
10
+ if (nmIndex !== -1) {
11
+ return key.substring(nmIndex + 'node_modules/'.length);
12
+ }
13
+
14
+ return key;
15
+ }
16
+
17
+ function getComponentDir(key) {
18
+ const segments = key.split('/');
19
+
20
+ if ((key.indexOf('@') === 0 && segments.length <= 2) || segments.length <= 1) {
21
+ return `${key}/`;
22
+ }
23
+
24
+ return `${segments.slice(0, -1).join('/')}/`;
25
+ }
26
+
27
+ function addUnique(list, item) {
28
+ if (list.indexOf(item) === -1) {
29
+ list.push(item);
30
+ }
31
+ }
32
+
33
+ function isNodeModulesUsingComponent(name) {
34
+ const searchKey = normalizeComponentKey(name);
35
+
36
+ if (nodeModulesUsingComponent.indexOf(searchKey) !== -1) {
37
+ return true;
38
+ }
39
+
40
+ return nodeModulesUsingComponentDirs.some((componentDir) => {
41
+ return searchKey.indexOf(componentDir) === 0;
42
+ });
8
43
  }
9
44
 
10
45
  function addNodeModulesUsingComponent(item) {
11
- nodeModulesUsingComponent.push(item);
46
+ const key = normalizeComponentKey(item);
47
+
48
+ addUnique(nodeModulesUsingComponent, key);
49
+ addUnique(nodeModulesUsingComponentDirs, getComponentDir(key));
12
50
  }
13
51
 
14
52
  module.exports = {
@@ -13,6 +13,7 @@ const { getBuildEnv } = require('./utils/buildEnv');
13
13
  const { getConfig } = require('./config/getConfig');
14
14
  const { getEntries } = require('./config/getEntries');
15
15
  const { getAppConfig } = require('./config/getAppConfig');
16
+ const { isNodeModulesUsingComponent } = require('./utils/isNodeModulesUsingComponent');
16
17
 
17
18
  const { isSubpackage } = require('./utils/isSubpackage');
18
19
  const { compatiblePath } = require('./utils/compatiblePath');
@@ -72,7 +73,18 @@ module.exports = async (options, { analyzer, quiet } = {}) => {
72
73
  return resource;
73
74
  };
74
75
 
76
+ const isNodeModulesComponentStyle = (resource) => {
77
+ return (
78
+ resource &&
79
+ PATTERNS.NODE_MODULES.test(resource) &&
80
+ PATTERNS.STYLE_EXTS.test(resource) &&
81
+ isNodeModulesUsingComponent(resource)
82
+ );
83
+ };
84
+
75
85
  const cacheGroups = {
86
+ default: false,
87
+ defaultVendors: false,
76
88
  vendors: {
77
89
  minChunks: 1,
78
90
  test(module) {
@@ -81,7 +93,7 @@ module.exports = async (options, { analyzer, quiet } = {}) => {
81
93
  if (resource === false) {
82
94
  return true;
83
95
  }
84
- if (PATTERNS.WXSS_EXT.test(resource)) {
96
+ if (PATTERNS.STYLE_EXTS.test(resource)) {
85
97
  return false;
86
98
  }
87
99
 
@@ -96,7 +108,23 @@ module.exports = async (options, { analyzer, quiet } = {}) => {
96
108
  },
97
109
  vendors_wxss: {
98
110
  minChunks: 2,
99
- test: PATTERNS.NODE_MODULES,
111
+ test(module) {
112
+ const resource = getResource(module);
113
+
114
+ if (resource === false) {
115
+ return false;
116
+ }
117
+
118
+ if (!PATTERNS.STYLE_EXTS.test(resource)) {
119
+ return false;
120
+ }
121
+
122
+ if (isNodeModulesComponentStyle(resource)) {
123
+ return false;
124
+ }
125
+
126
+ return PATTERNS.NODE_MODULES.test(resource);
127
+ },
100
128
  name: 'vendors_wxss',
101
129
  reuseExistingChunk: true,
102
130
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hw-weapp-compiler",
3
- "version": "1.0.15",
3
+ "version": "1.0.16",
4
4
  "description": "基于 webpack5 的小程序构建工具,兼容 Node.js 14~24",
5
5
  "main": "index.js",
6
6
  "bin": {