mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-03 11:22:30 +02:00
feat: allow user to modify generated webpack config
This commit is contained in:
parent
2b5ee3e869
commit
10b1a38762
9 changed files with 172 additions and 3 deletions
|
@ -3,6 +3,7 @@ const webpackNiceLog = require('webpack-nicelog');
|
|||
const {StatsWriterPlugin} = require('webpack-stats-plugin');
|
||||
const cleanWebpackPlugin = require('clean-webpack-plugin');
|
||||
const createBaseConfig = require('./base');
|
||||
const {applyChainWebpack} = require('./utils');
|
||||
|
||||
module.exports = function createClientConfig(props) {
|
||||
const config = createBaseConfig(props);
|
||||
|
@ -21,5 +22,9 @@ module.exports = function createClientConfig(props) {
|
|||
|
||||
// show compilation progress bar and build time
|
||||
config.plugin('niceLog').use(webpackNiceLog, [{name: 'Client'}]);
|
||||
|
||||
// user extended webpack-chain config
|
||||
applyChainWebpack(props.siteConfig.chainWebpack, config, false);
|
||||
|
||||
return config;
|
||||
};
|
||||
|
|
|
@ -2,6 +2,7 @@ const path = require('path');
|
|||
const staticSiteGenerator = require('static-site-generator-webpack-plugin');
|
||||
const webpackNiceLog = require('webpack-nicelog');
|
||||
const createBaseConfig = require('./base');
|
||||
const {applyChainWebpack} = require('./utils');
|
||||
|
||||
module.exports = function createServerConfig(props) {
|
||||
const config = createBaseConfig(props, true);
|
||||
|
@ -32,5 +33,8 @@ module.exports = function createServerConfig(props) {
|
|||
.plugin('niceLog')
|
||||
.use(webpackNiceLog, [{name: 'Server', color: 'yellow'}]);
|
||||
|
||||
// user extended webpack-chain config
|
||||
applyChainWebpack(props.siteConfig.chainWebpack, config, true);
|
||||
|
||||
return config;
|
||||
};
|
||||
|
|
28
lib/webpack/utils.js
Normal file
28
lib/webpack/utils.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
const merge = require('webpack-merge');
|
||||
|
||||
// Modify the generated webpack config with normal webpack config
|
||||
function applyConfigureWebpack(userConfig, config, isServer) {
|
||||
if (typeof userConfig === 'object') {
|
||||
return merge(config, userConfig);
|
||||
}
|
||||
if (typeof userConfig === 'function') {
|
||||
const res = userConfig(config, isServer);
|
||||
if (res && typeof res === 'object') {
|
||||
return merge(config, res);
|
||||
}
|
||||
}
|
||||
return config;
|
||||
}
|
||||
|
||||
// Modify the generated webpack config with webpack-chain API
|
||||
function applyChainWebpack(userChainWebpack, config, isServer) {
|
||||
if (userChainWebpack) {
|
||||
userChainWebpack(config, isServer);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
applyConfigureWebpack,
|
||||
applyChainWebpack
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue