Skip to content

Commit

Permalink
core: extract config.css options
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Oct 10, 2018
1 parent 3ac6011 commit 3733cf3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 6 additions & 0 deletions packages/core/config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ exports.babel = {
]
}

exports.css = {
modules: true,
importLoaders: 1,
localIdentName: '[local]__[hash:base64:5]'
}

// Any PostCSS config
// ~> "strings" will be required
exports.postcss = {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = function (src, config, opts) {
let isProd = opts.production;
let bundle = ['./index.js'];

let { babel, postcss, terser } = config;
let { babel, css, postcss, terser } = config;
let extns = ['.wasm', '.mjs', '.js', '.json']; // webpack defaults

// Customize "targets.browsers" w/ ESM warning
Expand All @@ -26,7 +26,7 @@ module.exports = function (src, config, opts) {
});

// Construct Style rules
let styles = require('./style')(postcss, opts);
let styles = require('./style')(postcss, css, opts);

if (!isProd) {
bundle.push(
Expand Down
14 changes: 5 additions & 9 deletions packages/core/webpack/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function generate(isProd, name, options) {
return (name += '-loader') && { loader:name, options };
}

module.exports = function (postcss, opts) {
module.exports = function (postcss, css, opts) {
// Throw if `postcss.plugin` is a fn
if (typeof postcss.plugins === 'function') {
throw new Error('PostCSS "plugins" config cannot be a function');
Expand All @@ -14,7 +14,7 @@ module.exports = function (postcss, opts) {
let { src, production } = opts;
let fn = generate.bind(null, production);
let test, plugins=[], rules=[], paths=['node_modules'];
let ext, filename, chunkFilename, extns=[];
let ext, extns=[];

let obj = {
css: [],
Expand All @@ -26,13 +26,9 @@ module.exports = function (postcss, opts) {
};

// assume dev/HMR values initially
let css={}, fallback='style-loader';
chunkFilename = '[id].chunk.css';
filename = '[name].css';

css.localIdentName = '[local]__[hash:base64:5]';
css.importLoaders = 1;
css.modules = true;
let fallback = 'style-loader';
let chunkFilename = '[id].chunk.css';
let filename = '[name].css';

if (production) {
fallback = ExtractCSS.loader; // prepare extraction
Expand Down

0 comments on commit 3733cf3

Please sign in to comment.