Skip to content

Commit c18ebe6

Browse files
committed
fixed cache problem in watch mode
1 parent 7944405 commit c18ebe6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "rollup-plugin-import-css",
33
"type": "module",
4-
"version": "4.1.0",
4+
"version": "4.1.1",
55
"description": "A Rollup plugin to import CSS into JavaScript",
66
"main": "dist/plugin.cjs",
77
"module": "dist/plugin.js",

src/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,13 @@ export default (options = {}) => {
146146
return;
147147
}
148148

149+
/* create a copy of the styles object that we can modify to avoid caching problems in watch mode */
150+
const stylesToEmit = Object.assign({}, styles);
151+
149152
/* copy relative assets to the output directory and update the referenced path */
150153
if (copyRelativeAssets) {
151154
for (let id of stylesheets) {
152-
const assets = [...styles[id].matchAll(/url\(\s*(['"]?)(\.\/.*?)\1\s*\)/g)].map((match) => match[2]);
155+
const assets = [...stylesToEmit[id].matchAll(/url\(\s*(['"]?)(\.\/.*?)\1\s*\)/g)].map((match) => match[2]);
153156

154157
for (let asset of assets) {
155158
const reference = this.emitFile({
@@ -158,13 +161,13 @@ export default (options = {}) => {
158161
source: fs.readFileSync(path.resolve(path.dirname(id), asset))
159162
});
160163

161-
styles[id] = styles[id].replace(asset, `./${this.getFileName(reference)}`);
164+
stylesToEmit[id] = styles[id].replace(asset, `./${this.getFileName(reference)}`);
162165
}
163166
}
164167
}
165168

166169
/* merge all css files into a single stylesheet */
167-
const css = stylesheets.map((id) => styles[id]).join(options.minify ? "" : "\n");
170+
const css = stylesheets.map((id) => stylesToEmit[id]).join(options.minify ? "" : "\n");
168171

169172
if (css.trim().length <= 0 && !alwaysOutput) return;
170173

0 commit comments

Comments
 (0)