Skip to content

Commit

Permalink
Prevent postcss-modules plugin config from being deleted after first …
Browse files Browse the repository at this point in the history
…run (#1589)
  • Loading branch information
maxholman authored and devongovett committed Jul 1, 2018
1 parent 14fabe9 commit 8599751
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/transforms/postcss.js
Expand Up @@ -28,8 +28,7 @@ async function getConfig(asset) {
return;
}

config = Object.assign({}, config);

config = config || {};
let postcssModulesConfig = {
getJSON: (filename, json) => (asset.cssModules = json)
};
Expand Down
2 changes: 1 addition & 1 deletion src/transforms/posthtml.js
Expand Up @@ -35,7 +35,7 @@ async function getConfig(asset) {
return;
}

config = Object.assign({}, config);
config = config || {};
const plugins = config.plugins;
if (typeof plugins === 'object') {
const depConfig = {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/config.js
@@ -1,5 +1,6 @@
const fs = require('./fs');
const path = require('path');
const clone = require('clone');

const PARSERS = {
json: require('json5').parse,
Expand Down Expand Up @@ -36,7 +37,7 @@ async function load(filepath, filenames, root = path.parse(filepath).root) {
try {
let extname = path.extname(configFile).slice(1);
if (extname === 'js') {
return require(configFile);
return clone(require(configFile));
}

let configContent = (await fs.readFile(configFile)).toString();
Expand Down
9 changes: 9 additions & 0 deletions test/css.js
Expand Up @@ -218,6 +218,15 @@ describe('css', function() {
assert(css.includes(`.${cssClass}`));
});

it('should support transforming with postcss twice with the same result', async function() {
let b = await bundle(__dirname + '/integration/postcss-plugins/index.js');
let c = await bundle(__dirname + '/integration/postcss-plugins/index2.js');

let [run1, run2] = await Promise.all([await run(b), await run(c)]);

assert.equal(run1(), run2());
});

it('should minify CSS in production mode', async function() {
let b = await bundle(__dirname + '/integration/cssnano/index.js', {
production: true
Expand Down
8 changes: 8 additions & 0 deletions test/integration/postcss-plugins/.postcssrc.js
@@ -0,0 +1,8 @@
module.exports = {
modules: true,
plugins: {
'postcss-modules': {
generateScopedName: "_[name]__[local]"
}
}
};
3 changes: 3 additions & 0 deletions test/integration/postcss-plugins/index.css
@@ -0,0 +1,3 @@
.index {
color: red;
}
5 changes: 5 additions & 0 deletions test/integration/postcss-plugins/index.js
@@ -0,0 +1,5 @@
var map = require('./index.css');

module.exports = function () {
return map.index;
};
5 changes: 5 additions & 0 deletions test/integration/postcss-plugins/index2.js
@@ -0,0 +1,5 @@
var map = require('./index.css');

module.exports = function () {
return map.index;
};

0 comments on commit 8599751

Please sign in to comment.