@unocss/webpack 0.32.13 → 0.33.2
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.
- package/dist/index.cjs +15 -3
- package/dist/index.mjs +15 -3
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -7,7 +7,7 @@ const WebpackSources = require('webpack-sources');
|
|
|
7
7
|
const core = require('@unocss/core');
|
|
8
8
|
const pluginutils = require('@rollup/pluginutils');
|
|
9
9
|
const config = require('@unocss/config');
|
|
10
|
-
require('crypto');
|
|
10
|
+
const crypto = require('crypto');
|
|
11
11
|
|
|
12
12
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
13
13
|
|
|
@@ -38,6 +38,10 @@ const LAYER_PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g
|
|
|
38
38
|
function getLayerPlaceholder(layer) {
|
|
39
39
|
return `#--unocss--{layer:${layer}}`;
|
|
40
40
|
}
|
|
41
|
+
const HASH_PLACEHOLDER_RE = /#--unocss-hash--\s*{\s*content\s*:\s*\\*"(.+?)\\*";?\s*}/g;
|
|
42
|
+
function getHashPlaceholder(hash) {
|
|
43
|
+
return `#--unocss-hash--{content:"${hash}"}`;
|
|
44
|
+
}
|
|
41
45
|
|
|
42
46
|
const INCLUDE_COMMENT = "@unocss-include";
|
|
43
47
|
const IGNORE_COMMENT = "@unocss-ignore";
|
|
@@ -116,6 +120,10 @@ function getPath(id) {
|
|
|
116
120
|
return id.replace(/\?.*$/, "");
|
|
117
121
|
}
|
|
118
122
|
|
|
123
|
+
function getHash(input, length = 8) {
|
|
124
|
+
return crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
125
|
+
}
|
|
126
|
+
|
|
119
127
|
const PLUGIN_NAME = "unocss:webpack";
|
|
120
128
|
const UPDATE_DEBOUNCE = 10;
|
|
121
129
|
function defineConfig(config) {
|
|
@@ -152,8 +160,9 @@ function WebpackPlugin(configOrPath, defaults) {
|
|
|
152
160
|
},
|
|
153
161
|
load(id) {
|
|
154
162
|
const layer = entries.get(getPath(id));
|
|
163
|
+
const hash = entries.get(`${id}_hash`);
|
|
155
164
|
if (layer)
|
|
156
|
-
return getLayerPlaceholder(layer);
|
|
165
|
+
return (hash ? getHashPlaceholder(hash) : "") + getLayerPlaceholder(layer);
|
|
157
166
|
},
|
|
158
167
|
webpack(compiler) {
|
|
159
168
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
@@ -164,6 +173,7 @@ function WebpackPlugin(configOrPath, defaults) {
|
|
|
164
173
|
for (const file of files) {
|
|
165
174
|
let code = compilation.assets[file].source().toString();
|
|
166
175
|
let replaced = false;
|
|
176
|
+
code = code.replace(HASH_PLACEHOLDER_RE, "");
|
|
167
177
|
code = code.replace(LAYER_PLACEHOLDER_RE, (_, quote, layer) => {
|
|
168
178
|
replaced = true;
|
|
169
179
|
const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries.values())) : result.getLayer(layer) || "";
|
|
@@ -186,11 +196,13 @@ function WebpackPlugin(configOrPath, defaults) {
|
|
|
186
196
|
return;
|
|
187
197
|
const result = await uno.generate(tokens);
|
|
188
198
|
Array.from(plugin.__vfsModules).forEach((id) => {
|
|
189
|
-
const path = id.slice(plugin.__virtualModulePrefix.length);
|
|
199
|
+
const path = id.slice(plugin.__virtualModulePrefix.length).replace(/\\/g, "/");
|
|
190
200
|
const layer = entries.get(path);
|
|
191
201
|
if (!layer)
|
|
192
202
|
return;
|
|
193
203
|
const code = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries.values())) : result.getLayer(layer) || "";
|
|
204
|
+
const hash = getHash(code);
|
|
205
|
+
entries.set(`${path}_hash`, hash);
|
|
194
206
|
plugin.__vfs.writeModule(id, code);
|
|
195
207
|
});
|
|
196
208
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import WebpackSources from 'webpack-sources';
|
|
|
3
3
|
import { cssIdRE, createGenerator, BetterMap } from '@unocss/core';
|
|
4
4
|
import { createFilter } from '@rollup/pluginutils';
|
|
5
5
|
import { loadConfig } from '@unocss/config';
|
|
6
|
-
import 'crypto';
|
|
6
|
+
import { createHash } from 'crypto';
|
|
7
7
|
|
|
8
8
|
const defaultExclude = [cssIdRE];
|
|
9
9
|
const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/];
|
|
@@ -30,6 +30,10 @@ const LAYER_PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g
|
|
|
30
30
|
function getLayerPlaceholder(layer) {
|
|
31
31
|
return `#--unocss--{layer:${layer}}`;
|
|
32
32
|
}
|
|
33
|
+
const HASH_PLACEHOLDER_RE = /#--unocss-hash--\s*{\s*content\s*:\s*\\*"(.+?)\\*";?\s*}/g;
|
|
34
|
+
function getHashPlaceholder(hash) {
|
|
35
|
+
return `#--unocss-hash--{content:"${hash}"}`;
|
|
36
|
+
}
|
|
33
37
|
|
|
34
38
|
const INCLUDE_COMMENT = "@unocss-include";
|
|
35
39
|
const IGNORE_COMMENT = "@unocss-ignore";
|
|
@@ -108,6 +112,10 @@ function getPath(id) {
|
|
|
108
112
|
return id.replace(/\?.*$/, "");
|
|
109
113
|
}
|
|
110
114
|
|
|
115
|
+
function getHash(input, length = 8) {
|
|
116
|
+
return createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
117
|
+
}
|
|
118
|
+
|
|
111
119
|
const PLUGIN_NAME = "unocss:webpack";
|
|
112
120
|
const UPDATE_DEBOUNCE = 10;
|
|
113
121
|
function defineConfig(config) {
|
|
@@ -144,8 +152,9 @@ function WebpackPlugin(configOrPath, defaults) {
|
|
|
144
152
|
},
|
|
145
153
|
load(id) {
|
|
146
154
|
const layer = entries.get(getPath(id));
|
|
155
|
+
const hash = entries.get(`${id}_hash`);
|
|
147
156
|
if (layer)
|
|
148
|
-
return getLayerPlaceholder(layer);
|
|
157
|
+
return (hash ? getHashPlaceholder(hash) : "") + getLayerPlaceholder(layer);
|
|
149
158
|
},
|
|
150
159
|
webpack(compiler) {
|
|
151
160
|
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
@@ -156,6 +165,7 @@ function WebpackPlugin(configOrPath, defaults) {
|
|
|
156
165
|
for (const file of files) {
|
|
157
166
|
let code = compilation.assets[file].source().toString();
|
|
158
167
|
let replaced = false;
|
|
168
|
+
code = code.replace(HASH_PLACEHOLDER_RE, "");
|
|
159
169
|
code = code.replace(LAYER_PLACEHOLDER_RE, (_, quote, layer) => {
|
|
160
170
|
replaced = true;
|
|
161
171
|
const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries.values())) : result.getLayer(layer) || "";
|
|
@@ -178,11 +188,13 @@ function WebpackPlugin(configOrPath, defaults) {
|
|
|
178
188
|
return;
|
|
179
189
|
const result = await uno.generate(tokens);
|
|
180
190
|
Array.from(plugin.__vfsModules).forEach((id) => {
|
|
181
|
-
const path = id.slice(plugin.__virtualModulePrefix.length);
|
|
191
|
+
const path = id.slice(plugin.__virtualModulePrefix.length).replace(/\\/g, "/");
|
|
182
192
|
const layer = entries.get(path);
|
|
183
193
|
if (!layer)
|
|
184
194
|
return;
|
|
185
195
|
const code = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries.values())) : result.getLayer(layer) || "";
|
|
196
|
+
const hash = getHash(code);
|
|
197
|
+
entries.set(`${path}_hash`, hash);
|
|
186
198
|
plugin.__vfs.writeModule(id, code);
|
|
187
199
|
});
|
|
188
200
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/webpack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.2",
|
|
4
4
|
"description": "The Webpack plugin for UnoCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@rollup/pluginutils": "^4.2.1",
|
|
40
|
-
"@unocss/config": "0.
|
|
41
|
-
"@unocss/core": "0.
|
|
40
|
+
"@unocss/config": "0.33.2",
|
|
41
|
+
"@unocss/core": "0.33.2",
|
|
42
42
|
"unplugin": "^0.6.2",
|
|
43
43
|
"webpack-sources": "^3.2.3"
|
|
44
44
|
},
|