Skip to content

Commit

Permalink
refactor: postcss and framework set
Browse files Browse the repository at this point in the history
  • Loading branch information
hubcarl committed Nov 19, 2018
1 parent df3564c commit b489abe
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports.base = {
install:{
check: false
},
postcss: true,
compile:{
cache: true,
thread: true
Expand Down
4 changes: 4 additions & 0 deletions lib/core/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class Config {
return false;
}

get postcss() {
return this.config.postcss;
}

get framework() {
return this.config.framework;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/core/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ module.exports = {
itemLoader.use[index] = this.merge(itemLoader.use[index], options);
}
});
if (itemLoader.postcss) {
if (this.postcss && itemLoader.postcss) {
const postcssIndex = ['css', 'css_module'].includes(name) ? itemLoader.use.length : itemLoader.use.length - 1;
const postcssLoader = this.createPostCssLoader(loaderOptions && loaderOptions.postcss);
itemLoader.use.splice(postcssIndex, 0, postcssLoader);
Expand Down
1 change: 1 addition & 0 deletions test/client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,7 @@ describe('client.test.js', () => {
const scssLoader = helper.getLoaderByName('sass', webpackConfig.module.rules, /\.scss/);
const lessLoader = helper.getLoaderByName('less', webpackConfig.module.rules, /\.less/);
const stylusLoader = helper.getLoaderByName('stylus', webpackConfig.module.rules, /\.stylus/);

expect(cssLoader.use[1].options.sourceMap).to.be.false;
expect(sassLoader.use[1].options.sourceMap).to.be.false;
expect(sassLoader.use[3].options.sourceMap).to.be.false;
Expand Down
19 changes: 19 additions & 0 deletions test/rule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,24 @@ describe('rules.test.js', () => {
expect(helper.getLoaderByName('babel', rules)).to.be.undefined;
expect(helper.getLoaderByName(/\.(woff2?|eot|ttf|otf)(\?.*)?$/, rules)).to.be.undefined;
});

it('should webpack rules options test', () => {
const config = {
module: {
rules: [
{
eslint: {
fix: true
}
}
]
}
};
const builder = helper.createBuilder(config);
const webpackConfig = builder.create();
const rules = webpackConfig.module.rules;
const eslint = helper.getLoaderByName('eslint', rules);
expect(eslint.use[0].options.fix).to.be.true;
});
});
});
2 changes: 2 additions & 0 deletions utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ utils.getLoaderLabel = loader => {
}
return name;
}, '');
} else if (Object.keys(loader).length === 1) {
loaderName = Object.keys(loader)[0];
}
}
return loaderName.replace(/-loader$/, '');
Expand Down

0 comments on commit b489abe

Please sign in to comment.