Skip to content

Instantly share code, notes, and snippets.

@robatwilliams
Created November 28, 2018 09:54
Show Gist options
  • Save robatwilliams/05359c84570b6fa466a84148eb057b16 to your computer and use it in GitHub Desktop.
Save robatwilliams/05359c84570b6fa466a84148eb057b16 to your computer and use it in GitHub Desktop.
Organising webpack config
const dependencyCssRule = {
};
function sassRule(options) {
return {
test: 1,
use: [
// use options.prod to turn off sourcemaps
// use options.prod to set sass outputStyle compressed/not
]
};
}
module.exports = { dependencyCssRule, sassRule };
module.exports = (env, argv, options) => {
return {
context: 1,
entry: 1,
externals: 1,
module: {
rules: [
]
},
output: 1,
resolve: {
modules: [
path.resolve(rootPath, 'src'), // avoid ../.. hell in imports
'node_modules',
]
}
};
};
const blocks = require('./webpack.blocks');
const createCommonConfig = require('./webpack.config.common');
module.exports = (env, argv) => {
const options = {};
const commonConfig = createCommonConfig(env, argv, options);
const sassRule = configBlocks.sassRule(options);
return {
...commonConfig,
devServer: 1,
devtool: 1,
mode: 'development',
module: {
rules: [
...commonConfig.module.rules,
configBlocks.dependencyCssRule,
{ }, {
test: sassRule.test,
use: [
'style-loader',
...sassRule.use,
]
}
]
},
performance: 1,
plugins: 1,
};
};
module.exports = (env, argv) => {
const options = { prod: true };
const commonConfig = createCommonConfig(env, argv, options);
const sassRule = configBlocks.sassRule(options);
return {
...commonConfig,
bail: 1,
devtool: 1,
mode: 'production',
module: {
rules: [
...commonConfig.module.rules,
{
test: sassRule.test,
use: ExtractTextWebpackPlugin.extract({
use: sassRule.use,
}),
}
]
},
optimization: 1, // uglify: no parallel, sourcemep true, warningsFilter sourceAbsPath && !includes 'node_modules' uglifyOptions output.comments=some, warnings=true
output: {
...commonConfig.output,
path: rootPath,
},
performance: 1,
plugins: 1,
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment