Skip to content

Commit 4fa2cf5

Browse files
committed
feat: 配置项初始化修改
1 parent 91c4068 commit 4fa2cf5

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

packages/beidou-webpack/config/webpack/webpack.browser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const {
1515

1616
module.exports = (app, entry, dev) => {
1717
const config = common(app, entry, dev);
18-
app.webpackFactory.reset(config);
18+
app.webpackFactory.append(config);
1919
app.webpackFactory.addRules([
2020
{
2121
test: /\.(js|jsx|mjs)$/,

packages/beidou-webpack/lib/factory/Webpack.js

+9
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,15 @@ class WebpackFactory extends Factory {
123123
return this;
124124
}
125125

126+
append(config) {
127+
if (this.getEnv()) {
128+
this._webpackConfig = Object.assign(this._webpackConfig, config);
129+
} else {
130+
Object.getPrototypeOf(this)._webpackConfig = Object.assign(Object.getPrototypeOf(this)._webpackConfig, config);
131+
}
132+
return this;
133+
}
134+
126135
get(key, filter) {
127136
const keyData = this._localConfig()[key];
128137
if (!keyData && filter) {

packages/beidou-webpack/lib/utils/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const getWebpackConfig = (app, options = {}, target = 'browser') => {
8383
const isDev = app.config.env !== 'prod';
8484
let webpackConfig = null;
8585
app.webpackFactory = new WebpackFactory();
86-
app.webpackFactory.reset();
86+
Object.getPrototypeOf(app.webpackFactory).init();
8787
const defaultConfigPath = path.join(
8888
__dirname,
8989
`../../config/webpack/webpack.${target}.js`
@@ -105,7 +105,6 @@ const getWebpackConfig = (app, options = {}, target = 'browser') => {
105105
debug('entry auto load as below:\n%o', entry);
106106

107107
webpackConfig = loadFile(defaultConfigPath, app, entry, isDev);
108-
109108
const customConfigPath = getCustomWebpackCfgPath(app);
110109
// custom config exists
111110
if (customConfigPath) {
@@ -143,6 +142,7 @@ const getWebpackConfig = (app, options = {}, target = 'browser') => {
143142
if (!devServer.publicPath) {
144143
devServer.publicPath = webpackConfig.output.publicPath || '/build';
145144
}
145+
146146
return webpackConfig;
147147
};
148148

0 commit comments

Comments
 (0)