Skip to content

Commit 7ad7545

Browse files
committed
Fixed partial file updates producing duplicate styles
1 parent c29a2aa commit 7ad7545

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

lib/loader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ module.exports = function (source, map) {
9292
});
9393

9494
if ('_emitThemePartial' in loader) {
95-
loader._emitThemePartial(result.css);
95+
loader._emitThemePartial(loader.resourcePath, result.css);
9696
} else {
9797
throw new Error('Theme loader missing _emitThemePartial function. Did you forget to include the ThemePlugin?');
9898
}

lib/plugin.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,28 @@ function ThemePlugin(options) {
6969

7070
ThemePlugin.prototype.apply = function apply(compiler) {
7171
const themes = this.options.themes;
72-
const themePartials = [];
72+
const themePartials = {};
7373

7474
compiler.plugin('compilation', compilation => {
7575
compilation.plugin('normal-module-loader', (context, module) => {
76-
context._emitThemePartial = (themeSource) => {
77-
themePartials.push(themeSource);
76+
context._emitThemePartial = (resourcePath, themeSource) => {
77+
themePartials[resourcePath] = themeSource;
7878
};
7979
});
8080
});
8181

8282
compiler.plugin('emit', (compilation, done) => {
83-
if (themePartials.length === 0) {
83+
const themePartialResources = Object.keys(themePartials);
84+
85+
if (themePartialResources.length === 0) {
8486
done();
8587
return;
8688
}
8789

8890
// Concat theme partials
89-
const source = themePartials.join('\n');
91+
const source = themePartialResources
92+
.map(resourcePath => themePartials[resourcePath])
93+
.join('\n');
9094

9195
generateThemes(themes, source).then(function (results) {
9296
const themeAssets = results.reduce((acc, theme) => {

0 commit comments

Comments
 (0)