@dcloudio/uni-cli-shared 3.0.0-alpha-3061620221230001 → 3.0.0-alpha-3061620230106001
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.
|
@@ -34,7 +34,8 @@ export declare function cssPlugin(config: ResolvedConfig): Plugin;
|
|
|
34
34
|
/**
|
|
35
35
|
* Plugin applied after user plugins
|
|
36
36
|
*/
|
|
37
|
-
export declare function cssPostPlugin(config: ResolvedConfig, { chunkCssFilename, chunkCssCode, }: {
|
|
37
|
+
export declare function cssPostPlugin(config: ResolvedConfig, { platform, chunkCssFilename, chunkCssCode, }: {
|
|
38
|
+
platform: UniApp.PLATFORM;
|
|
38
39
|
chunkCssFilename: (id: string) => string | void;
|
|
39
40
|
chunkCssCode: (filename: string, cssCode: string) => Promise<string> | string;
|
|
40
41
|
}): Plugin;
|
|
@@ -39,6 +39,7 @@ const magic_string_1 = __importDefault(require("magic-string"));
|
|
|
39
39
|
const preprocess_1 = require("../../../../preprocess");
|
|
40
40
|
const cleanString_1 = require("../cleanString");
|
|
41
41
|
const shared_1 = require("@vue/shared");
|
|
42
|
+
const constants_1 = require("../../../../constants");
|
|
42
43
|
const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`;
|
|
43
44
|
exports.cssLangRE = new RegExp(cssLangs);
|
|
44
45
|
const cssModuleRE = new RegExp(`\\.module${cssLangs}`);
|
|
@@ -107,10 +108,38 @@ function cssPlugin(config) {
|
|
|
107
108
|
};
|
|
108
109
|
}
|
|
109
110
|
exports.cssPlugin = cssPlugin;
|
|
111
|
+
function findCssModuleIds(moduleId, cssModuleIds, seen) {
|
|
112
|
+
if (!cssModuleIds) {
|
|
113
|
+
cssModuleIds = new Set();
|
|
114
|
+
}
|
|
115
|
+
if (!seen) {
|
|
116
|
+
seen = new Set();
|
|
117
|
+
}
|
|
118
|
+
if (seen.has(moduleId)) {
|
|
119
|
+
return cssModuleIds;
|
|
120
|
+
}
|
|
121
|
+
seen.add(moduleId);
|
|
122
|
+
const moduleInfo = this.getModuleInfo(moduleId);
|
|
123
|
+
if (moduleInfo) {
|
|
124
|
+
moduleInfo.importedIds.forEach((id) => {
|
|
125
|
+
if (id.includes(constants_1.PAGES_JSON_JS)) {
|
|
126
|
+
// 查询main.js时,需要忽略pages.json.js,否则会把所有页面样式加进来
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
if (exports.cssLangRE.test(id) && !exports.commonjsProxyRE.test(id)) {
|
|
130
|
+
cssModuleIds.add(id);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
findCssModuleIds.call(this, id, cssModuleIds, seen);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return cssModuleIds;
|
|
138
|
+
}
|
|
110
139
|
/**
|
|
111
140
|
* Plugin applied after user plugins
|
|
112
141
|
*/
|
|
113
|
-
function cssPostPlugin(config, { chunkCssFilename, chunkCssCode, }) {
|
|
142
|
+
function cssPostPlugin(config, { platform, chunkCssFilename, chunkCssCode, }) {
|
|
114
143
|
// styles initialization in buildStart causes a styling loss in watch
|
|
115
144
|
const styles = new Map();
|
|
116
145
|
let cssChunks;
|
|
@@ -140,13 +169,37 @@ function cssPostPlugin(config, { chunkCssFilename, chunkCssCode, }) {
|
|
|
140
169
|
if (id) {
|
|
141
170
|
const filename = chunkCssFilename(id);
|
|
142
171
|
if (filename) {
|
|
143
|
-
|
|
144
|
-
|
|
172
|
+
if (platform === 'app' && filename === 'app.css') {
|
|
173
|
+
// 获取 unocss 的样式文件信息
|
|
174
|
+
const ids = Object.keys(chunk.modules).filter((id) => styles.has(id) &&
|
|
175
|
+
(id.includes('__uno.css') || id.includes('-unocss-')));
|
|
176
|
+
cssChunks.set(filename, ids);
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const ids = Object.keys(chunk.modules).filter((id) => styles.has(id));
|
|
180
|
+
cssChunks.set(filename, ids);
|
|
181
|
+
}
|
|
145
182
|
}
|
|
146
183
|
}
|
|
147
184
|
return null;
|
|
148
185
|
},
|
|
149
186
|
async generateBundle() {
|
|
187
|
+
// app 平台页面并未 chunk,所以 renderChunk 并不会处理页面的 css,需要这里再补充查找
|
|
188
|
+
if (platform === 'app') {
|
|
189
|
+
const moduleIds = Array.from(this.getModuleIds());
|
|
190
|
+
moduleIds.forEach((id) => {
|
|
191
|
+
const filename = chunkCssFilename(id);
|
|
192
|
+
if (filename) {
|
|
193
|
+
const ids = findCssModuleIds.call(this, id);
|
|
194
|
+
if (cssChunks.has(filename)) {
|
|
195
|
+
cssChunks.get(filename).forEach((id) => {
|
|
196
|
+
ids.add(id);
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
cssChunks.set(filename, [...ids]);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
150
203
|
if (!cssChunks.size) {
|
|
151
204
|
return;
|
|
152
205
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "3.0.0-alpha-
|
|
3
|
+
"version": "3.0.0-alpha-3061620230106001",
|
|
4
4
|
"description": "@dcloudio/uni-cli-shared",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"@babel/core": "^7.20.5",
|
|
26
26
|
"@babel/parser": "^7.20.5",
|
|
27
27
|
"@babel/types": "^7.20.7",
|
|
28
|
-
"@dcloudio/uni-i18n": "3.0.0-alpha-
|
|
29
|
-
"@dcloudio/uni-shared": "3.0.0-alpha-
|
|
28
|
+
"@dcloudio/uni-i18n": "3.0.0-alpha-3061620230106001",
|
|
29
|
+
"@dcloudio/uni-shared": "3.0.0-alpha-3061620230106001",
|
|
30
30
|
"@intlify/core-base": "9.1.9",
|
|
31
31
|
"@intlify/shared": "9.1.9",
|
|
32
32
|
"@intlify/vue-devtools": "9.1.9",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
},
|
|
65
65
|
"gitHead": "33e807d66e1fe47e2ee08ad9c59247e37b8884da",
|
|
66
66
|
"devDependencies": {
|
|
67
|
-
"@dcloudio/uni-uts-v1": "3.0.0-alpha-
|
|
67
|
+
"@dcloudio/uni-uts-v1": "3.0.0-alpha-3061620230106001",
|
|
68
68
|
"@types/babel__core": "^7.1.19",
|
|
69
69
|
"@types/debug": "^4.1.7",
|
|
70
70
|
"@types/estree": "^0.0.51",
|