diff --git a/src/transforms/postcss.js b/src/transforms/postcss.js index bae4b02c78b..90898e807d6 100644 --- a/src/transforms/postcss.js +++ b/src/transforms/postcss.js @@ -28,8 +28,7 @@ async function getConfig(asset) { return; } - config = Object.assign({}, config); - + config = config || {}; let postcssModulesConfig = { getJSON: (filename, json) => (asset.cssModules = json) }; diff --git a/src/transforms/posthtml.js b/src/transforms/posthtml.js index 59f0f586b4c..f12219bc7eb 100644 --- a/src/transforms/posthtml.js +++ b/src/transforms/posthtml.js @@ -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 = { diff --git a/src/utils/config.js b/src/utils/config.js index 6558662b8c7..7fd06af210d 100644 --- a/src/utils/config.js +++ b/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, @@ -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(); diff --git a/test/css.js b/test/css.js index 78dd3eca724..a880dc85280 100644 --- a/test/css.js +++ b/test/css.js @@ -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 diff --git a/test/integration/postcss-plugins/.postcssrc.js b/test/integration/postcss-plugins/.postcssrc.js new file mode 100644 index 00000000000..759fad17515 --- /dev/null +++ b/test/integration/postcss-plugins/.postcssrc.js @@ -0,0 +1,8 @@ +module.exports = { + modules: true, + plugins: { + 'postcss-modules': { + generateScopedName: "_[name]__[local]" + } + } +}; diff --git a/test/integration/postcss-plugins/index.css b/test/integration/postcss-plugins/index.css new file mode 100644 index 00000000000..27cc739e609 --- /dev/null +++ b/test/integration/postcss-plugins/index.css @@ -0,0 +1,3 @@ +.index { + color: red; +} diff --git a/test/integration/postcss-plugins/index.js b/test/integration/postcss-plugins/index.js new file mode 100644 index 00000000000..1ea1c50046f --- /dev/null +++ b/test/integration/postcss-plugins/index.js @@ -0,0 +1,5 @@ +var map = require('./index.css'); + +module.exports = function () { + return map.index; +}; diff --git a/test/integration/postcss-plugins/index2.js b/test/integration/postcss-plugins/index2.js new file mode 100644 index 00000000000..1ea1c50046f --- /dev/null +++ b/test/integration/postcss-plugins/index2.js @@ -0,0 +1,5 @@ +var map = require('./index.css'); + +module.exports = function () { + return map.index; +};