@unocss/webpack
Advanced tools
Comparing version 0.9.0 to 0.9.1
@@ -33,4 +33,4 @@ var __create = Object.create; | ||
var import_unplugin = __toModule(require("unplugin")); | ||
var import_pluginutils = __toModule(require("@rollup/pluginutils")); | ||
var import_webpack_sources = __toModule(require("webpack-sources")); | ||
var import_pluginutils = __toModule(require("@rollup/pluginutils")); | ||
@@ -51,3 +51,3 @@ // ../vite/src/utils.ts | ||
]; | ||
var PLACEHOLDER_RE = /#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g; | ||
var PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g; | ||
var ALL_LAYERS = "__ALL__"; | ||
@@ -68,2 +68,5 @@ function resolveId(id) { | ||
} | ||
function getLayerPlaceholder(layer) { | ||
return `#--unocss--{layer:${layer}}`; | ||
} | ||
@@ -84,4 +87,3 @@ // src/index.ts | ||
const entries = new Map(); | ||
const isDev = !!process.env.WEBPACK_DEV_SERVER; | ||
let devInitialized = false; | ||
const isDev = !!process.env.WEBPACK_DEV_SERVER || process.env.NODE_ENV === "development"; | ||
const plugin = { | ||
@@ -105,32 +107,30 @@ name: "unocss:webpack", | ||
}, | ||
load: isDev ? void 0 : (id) => { | ||
load(id) { | ||
const layer = entries.get(getPath(id)); | ||
if (layer) | ||
return `#--unocss--{layer:${layer}}`; | ||
return getLayerPlaceholder(layer); | ||
}, | ||
webpack(compiler) { | ||
if (!isDev) { | ||
compiler.hooks.compilation.tap(name, (compilation) => { | ||
compilation.hooks.optimizeAssets.tapPromise(name, async () => { | ||
const files = Object.keys(compilation.assets).filter((i) => i.endsWith(".css")); | ||
await Promise.all(tasks); | ||
const result = await uno.generate(tokens, { layerComments: false }); | ||
for (const file of files) { | ||
let code = compilation.assets[file].source().toString(); | ||
let replaced = false; | ||
code = code.replace(PLACEHOLDER_RE, (_, layer) => { | ||
replaced = true; | ||
return layer === ALL_LAYERS ? result.getLayers(void 0, Array.from(entries.values())) : result.getLayer(layer) || ""; | ||
}); | ||
if (replaced) | ||
compilation.assets[file] = new import_webpack_sources.RawSource(code); | ||
} | ||
}); | ||
compiler.hooks.compilation.tap(name, (compilation) => { | ||
compilation.hooks.optimizeAssets.tapPromise(name, async () => { | ||
const files = Object.keys(compilation.assets); | ||
await Promise.all(tasks); | ||
const result = await uno.generate(tokens, { layerComments: false }); | ||
for (const file of files) { | ||
let code = compilation.assets[file].source().toString(); | ||
let replaced = false; | ||
code = code.replace(PLACEHOLDER_RE, (_, quote, layer) => { | ||
replaced = true; | ||
const css = layer === ALL_LAYERS ? result.getLayers(void 0, Array.from(entries.values())) : result.getLayer(layer) || ""; | ||
if (!quote) | ||
return css; | ||
let escaped = JSON.stringify(css).slice(1, -1); | ||
if (quote === '\\"') | ||
escaped = JSON.stringify(escaped).slice(1, -1); | ||
return quote + escaped; | ||
}); | ||
if (replaced) | ||
compilation.assets[file] = new import_webpack_sources.default.RawSource(code); | ||
} | ||
}); | ||
} | ||
compiler.hooks.done.tap("done", () => { | ||
if (isDev && !devInitialized) { | ||
devInitialized = true; | ||
updateModules(); | ||
} | ||
}); | ||
@@ -137,0 +137,0 @@ } |
{ | ||
"name": "@unocss/webpack", | ||
"version": "0.9.0", | ||
"version": "0.9.1", | ||
"description": "The Webpack plugin for UnoCSS", | ||
@@ -36,4 +36,4 @@ "keywords": [ | ||
"@rollup/pluginutils": "^4.1.1", | ||
"@unocss/config": "0.9.0", | ||
"@unocss/core": "0.9.0", | ||
"@unocss/config": "0.9.1", | ||
"@unocss/core": "0.9.1", | ||
"unplugin": "^0.2.20", | ||
@@ -40,0 +40,0 @@ "webpack-sources": "^3.2.1" |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14162
4
+ Added@unocss/config@0.9.1(transitive)
+ Added@unocss/core@0.9.1(transitive)
- Removed@unocss/config@0.9.0(transitive)
- Removed@unocss/core@0.9.0(transitive)
Updated@unocss/config@0.9.1
Updated@unocss/core@0.9.1