@unocss/webpack 0.11.6 → 0.12.0
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.d.ts +2 -2
- package/dist/index.js +61 -21
- package/dist/index.mjs +61 -21
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as webpack from 'webpack';
|
|
|
2
2
|
import { UserConfig, UserConfigDefaults } from '@unocss/core';
|
|
3
3
|
|
|
4
4
|
declare type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
|
|
5
|
-
interface
|
|
5
|
+
interface PluginConfig<Theme extends {} = {}> extends UserConfig<Theme> {
|
|
6
6
|
/**
|
|
7
7
|
* Patterns that filter the files being extracted.
|
|
8
8
|
*/
|
|
@@ -13,7 +13,7 @@ interface PluginOptions<Theme extends {} = {}> extends UserConfig<Theme> {
|
|
|
13
13
|
exclude?: FilterPattern;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
interface WebpackPluginOptions<Theme extends {} = {}> extends
|
|
16
|
+
interface WebpackPluginOptions<Theme extends {} = {}> extends PluginConfig<Theme> {
|
|
17
17
|
}
|
|
18
18
|
declare function defineConfig<Theme extends {}>(config: WebpackPluginOptions<Theme>): WebpackPluginOptions<Theme>;
|
|
19
19
|
declare function WebpackPlugin(configOrPath?: WebpackPluginOptions | string, defaults?: UserConfigDefaults): webpack.WebpackPluginInstance;
|
package/dist/index.js
CHANGED
|
@@ -27,10 +27,7 @@ __export(exports, {
|
|
|
27
27
|
default: () => WebpackPlugin,
|
|
28
28
|
defineConfig: () => defineConfig
|
|
29
29
|
});
|
|
30
|
-
var import_core = __toModule(require("@unocss/core"));
|
|
31
|
-
var import_config = __toModule(require("@unocss/config"));
|
|
32
30
|
var import_unplugin = __toModule(require("unplugin"));
|
|
33
|
-
var import_pluginutils = __toModule(require("@rollup/pluginutils"));
|
|
34
31
|
var import_webpack_sources = __toModule(require("webpack-sources"));
|
|
35
32
|
|
|
36
33
|
// ../plugins-common/utils.ts
|
|
@@ -67,6 +64,58 @@ function getLayerPlaceholder(layer) {
|
|
|
67
64
|
return `#--unocss--{layer:${layer}}`;
|
|
68
65
|
}
|
|
69
66
|
|
|
67
|
+
// ../plugins-common/constants.ts
|
|
68
|
+
var INCLUDE_COMMENT = "@unocss-include";
|
|
69
|
+
|
|
70
|
+
// ../plugins-common/context.ts
|
|
71
|
+
var import_pluginutils = __toModule(require("@rollup/pluginutils"));
|
|
72
|
+
var import_config = __toModule(require("@unocss/config"));
|
|
73
|
+
var import_core = __toModule(require("@unocss/core"));
|
|
74
|
+
function createContext(configOrPath, defaults = {}) {
|
|
75
|
+
const { config = {}, filepath } = (0, import_config.loadConfig)(configOrPath);
|
|
76
|
+
const uno = (0, import_core.createGenerator)(config, defaults);
|
|
77
|
+
const invalidations = [];
|
|
78
|
+
const modules = new import_core.BetterMap();
|
|
79
|
+
const tokens = new Set();
|
|
80
|
+
let rollupFilter = (0, import_pluginutils.createFilter)(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
81
|
+
function invalidate() {
|
|
82
|
+
invalidations.forEach((cb) => cb());
|
|
83
|
+
}
|
|
84
|
+
async function scan(code, id) {
|
|
85
|
+
if (id)
|
|
86
|
+
modules.set(id, code);
|
|
87
|
+
await uno.applyExtractors(code, id, tokens);
|
|
88
|
+
invalidate();
|
|
89
|
+
}
|
|
90
|
+
async function reloadConfig() {
|
|
91
|
+
if (!filepath)
|
|
92
|
+
return;
|
|
93
|
+
uno.setConfig((0, import_config.loadConfig)(filepath).config);
|
|
94
|
+
uno.config.envMode = "dev";
|
|
95
|
+
rollupFilter = (0, import_pluginutils.createFilter)(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
96
|
+
tokens.clear();
|
|
97
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
98
|
+
invalidate();
|
|
99
|
+
}
|
|
100
|
+
const filter = (code, id) => {
|
|
101
|
+
return code.includes(INCLUDE_COMMENT) || rollupFilter(id);
|
|
102
|
+
};
|
|
103
|
+
return {
|
|
104
|
+
tokens,
|
|
105
|
+
modules,
|
|
106
|
+
invalidate,
|
|
107
|
+
onInvalidate(fn) {
|
|
108
|
+
invalidations.push(fn);
|
|
109
|
+
},
|
|
110
|
+
filter,
|
|
111
|
+
reloadConfig,
|
|
112
|
+
uno,
|
|
113
|
+
extract: scan,
|
|
114
|
+
config,
|
|
115
|
+
configFilepath: filepath
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
70
119
|
// src/index.ts
|
|
71
120
|
var PLUGIN_NAME = "unocss:webpack";
|
|
72
121
|
var UPDATE_DEBOUNCE = 10;
|
|
@@ -75,21 +124,23 @@ function defineConfig(config) {
|
|
|
75
124
|
}
|
|
76
125
|
function WebpackPlugin(configOrPath, defaults) {
|
|
77
126
|
return (0, import_unplugin.createUnplugin)(() => {
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
127
|
+
const context = createContext(configOrPath, defaults);
|
|
128
|
+
const { uno, tokens, filter, extract, onInvalidate } = context;
|
|
129
|
+
let timer;
|
|
130
|
+
onInvalidate(() => {
|
|
131
|
+
clearTimeout(timer);
|
|
132
|
+
timer = setTimeout(updateModules, UPDATE_DEBOUNCE);
|
|
133
|
+
});
|
|
83
134
|
const tasks = [];
|
|
84
135
|
const entries = new Map();
|
|
85
136
|
const plugin = {
|
|
86
137
|
name: "unocss:webpack",
|
|
87
138
|
enforce: "pre",
|
|
88
139
|
transformInclude(id) {
|
|
89
|
-
return filter(id);
|
|
140
|
+
return filter("", id);
|
|
90
141
|
},
|
|
91
142
|
transform(code, id) {
|
|
92
|
-
tasks.push(
|
|
143
|
+
tasks.push(extract(code, id));
|
|
93
144
|
return null;
|
|
94
145
|
},
|
|
95
146
|
resolveId(id) {
|
|
@@ -131,17 +182,6 @@ function WebpackPlugin(configOrPath, defaults) {
|
|
|
131
182
|
});
|
|
132
183
|
}
|
|
133
184
|
};
|
|
134
|
-
async function scan(code, id) {
|
|
135
|
-
if (id)
|
|
136
|
-
modules.set(id, code);
|
|
137
|
-
await uno.applyExtractors(code, id, tokens);
|
|
138
|
-
scheduleUpdate();
|
|
139
|
-
}
|
|
140
|
-
let timer;
|
|
141
|
-
function scheduleUpdate() {
|
|
142
|
-
clearTimeout(timer);
|
|
143
|
-
timer = setTimeout(updateModules, UPDATE_DEBOUNCE);
|
|
144
|
-
}
|
|
145
185
|
async function updateModules() {
|
|
146
186
|
if (!plugin.__vfsModules)
|
|
147
187
|
return;
|
package/dist/index.mjs
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { BetterMap, createGenerator } from "@unocss/core";
|
|
3
|
-
import { loadConfig } from "@unocss/config";
|
|
4
2
|
import { createUnplugin } from "unplugin";
|
|
5
|
-
import { createFilter } from "@rollup/pluginutils";
|
|
6
3
|
import WebpackSources from "webpack-sources";
|
|
7
4
|
|
|
8
5
|
// ../plugins-common/utils.ts
|
|
@@ -39,6 +36,58 @@ function getLayerPlaceholder(layer) {
|
|
|
39
36
|
return `#--unocss--{layer:${layer}}`;
|
|
40
37
|
}
|
|
41
38
|
|
|
39
|
+
// ../plugins-common/constants.ts
|
|
40
|
+
var INCLUDE_COMMENT = "@unocss-include";
|
|
41
|
+
|
|
42
|
+
// ../plugins-common/context.ts
|
|
43
|
+
import { createFilter } from "@rollup/pluginutils";
|
|
44
|
+
import { loadConfig } from "@unocss/config";
|
|
45
|
+
import { BetterMap, createGenerator } from "@unocss/core";
|
|
46
|
+
function createContext(configOrPath, defaults = {}) {
|
|
47
|
+
const { config = {}, filepath } = loadConfig(configOrPath);
|
|
48
|
+
const uno = createGenerator(config, defaults);
|
|
49
|
+
const invalidations = [];
|
|
50
|
+
const modules = new BetterMap();
|
|
51
|
+
const tokens = new Set();
|
|
52
|
+
let rollupFilter = createFilter(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
53
|
+
function invalidate() {
|
|
54
|
+
invalidations.forEach((cb) => cb());
|
|
55
|
+
}
|
|
56
|
+
async function scan(code, id) {
|
|
57
|
+
if (id)
|
|
58
|
+
modules.set(id, code);
|
|
59
|
+
await uno.applyExtractors(code, id, tokens);
|
|
60
|
+
invalidate();
|
|
61
|
+
}
|
|
62
|
+
async function reloadConfig() {
|
|
63
|
+
if (!filepath)
|
|
64
|
+
return;
|
|
65
|
+
uno.setConfig(loadConfig(filepath).config);
|
|
66
|
+
uno.config.envMode = "dev";
|
|
67
|
+
rollupFilter = createFilter(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
68
|
+
tokens.clear();
|
|
69
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
70
|
+
invalidate();
|
|
71
|
+
}
|
|
72
|
+
const filter = (code, id) => {
|
|
73
|
+
return code.includes(INCLUDE_COMMENT) || rollupFilter(id);
|
|
74
|
+
};
|
|
75
|
+
return {
|
|
76
|
+
tokens,
|
|
77
|
+
modules,
|
|
78
|
+
invalidate,
|
|
79
|
+
onInvalidate(fn) {
|
|
80
|
+
invalidations.push(fn);
|
|
81
|
+
},
|
|
82
|
+
filter,
|
|
83
|
+
reloadConfig,
|
|
84
|
+
uno,
|
|
85
|
+
extract: scan,
|
|
86
|
+
config,
|
|
87
|
+
configFilepath: filepath
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
42
91
|
// src/index.ts
|
|
43
92
|
var PLUGIN_NAME = "unocss:webpack";
|
|
44
93
|
var UPDATE_DEBOUNCE = 10;
|
|
@@ -47,21 +96,23 @@ function defineConfig(config) {
|
|
|
47
96
|
}
|
|
48
97
|
function WebpackPlugin(configOrPath, defaults) {
|
|
49
98
|
return createUnplugin(() => {
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
99
|
+
const context = createContext(configOrPath, defaults);
|
|
100
|
+
const { uno, tokens, filter, extract, onInvalidate } = context;
|
|
101
|
+
let timer;
|
|
102
|
+
onInvalidate(() => {
|
|
103
|
+
clearTimeout(timer);
|
|
104
|
+
timer = setTimeout(updateModules, UPDATE_DEBOUNCE);
|
|
105
|
+
});
|
|
55
106
|
const tasks = [];
|
|
56
107
|
const entries = new Map();
|
|
57
108
|
const plugin = {
|
|
58
109
|
name: "unocss:webpack",
|
|
59
110
|
enforce: "pre",
|
|
60
111
|
transformInclude(id) {
|
|
61
|
-
return filter(id);
|
|
112
|
+
return filter("", id);
|
|
62
113
|
},
|
|
63
114
|
transform(code, id) {
|
|
64
|
-
tasks.push(
|
|
115
|
+
tasks.push(extract(code, id));
|
|
65
116
|
return null;
|
|
66
117
|
},
|
|
67
118
|
resolveId(id) {
|
|
@@ -103,17 +154,6 @@ function WebpackPlugin(configOrPath, defaults) {
|
|
|
103
154
|
});
|
|
104
155
|
}
|
|
105
156
|
};
|
|
106
|
-
async function scan(code, id) {
|
|
107
|
-
if (id)
|
|
108
|
-
modules.set(id, code);
|
|
109
|
-
await uno.applyExtractors(code, id, tokens);
|
|
110
|
-
scheduleUpdate();
|
|
111
|
-
}
|
|
112
|
-
let timer;
|
|
113
|
-
function scheduleUpdate() {
|
|
114
|
-
clearTimeout(timer);
|
|
115
|
-
timer = setTimeout(updateModules, UPDATE_DEBOUNCE);
|
|
116
|
-
}
|
|
117
157
|
async function updateModules() {
|
|
118
158
|
if (!plugin.__vfsModules)
|
|
119
159
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/webpack",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
4
|
"description": "The Webpack plugin for UnoCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@rollup/pluginutils": "^4.1.1",
|
|
36
|
-
"@unocss/config": "0.
|
|
37
|
-
"@unocss/core": "0.
|
|
36
|
+
"@unocss/config": "0.12.0",
|
|
37
|
+
"@unocss/core": "0.12.0",
|
|
38
38
|
"unplugin": "^0.2.20",
|
|
39
39
|
"webpack-sources": "^3.2.1"
|
|
40
40
|
},
|