Created
November 28, 2018 09:54
-
-
Save robatwilliams/05359c84570b6fa466a84148eb057b16 to your computer and use it in GitHub Desktop.
Organising webpack config
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | |
] | |
} | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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