Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
fix: 修复 configWebpack 缺少的 webpack 实例参数
Browse files Browse the repository at this point in the history
  • Loading branch information
yesmeck committed May 6, 2020
1 parent 9a325d6 commit 52cb52a
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/guide/advanced/plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export default lessPlugin;

- `params`
- `config` - `webpack-chain``Config 对象`
- `webpack` - Webpack 实例,用于获取 Webpack 内置插件。
- `addCSSRule` - 新增一条 CSS 处理规则。

### configBabel
Expand Down
7 changes: 6 additions & 1 deletion docs/guide/config/remax.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ _默认值:_ `true`
// remax.config.js

module.exports = {
configWebpack({ config }) {
configWebpack({ config, webpack }) {
// config 是的 [webpack-chain](https://github.com/neutrinojs/webpack-chain) Config 对象。
config.plugins.delete('webpackbar'); // 去掉进度条
config.plugin('custom-define').use(webpack.DefinePlugin, [
{
__MOCK__: JSON.stringify(process.env.MOCK),
},
]); // 新增一个 define 插件
},
};
```
Expand Down
2 changes: 1 addition & 1 deletion packages/remax-cli/src/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default class API {
}, true);
}

configWebpack(params: { config: Config; addCSSRule: (ruleConfig: RuleConfig) => void }) {
configWebpack(params: { config: Config; webpack: any; addCSSRule: (ruleConfig: RuleConfig) => void }) {
this.plugins.forEach(plugin => {
if (typeof plugin.configWebpack === 'function') {
plugin.configWebpack(params);
Expand Down
7 changes: 4 additions & 3 deletions packages/remax-cli/src/build/webpack/config.mini.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as path from 'path';
import { Configuration } from 'webpack';
import * as webpack from 'webpack';
import Config from 'webpack-chain';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import WebpackBar from 'webpackbar';
Expand Down Expand Up @@ -68,7 +68,7 @@ function resolveBabelConfig(options: Options) {
return false;
}

export default function webpackConfig(api: API, options: Options, target: Platform): Configuration {
export default function webpackConfig(api: API, options: Options, target: Platform): webpack.Configuration {
baseConfig(config, options, target);

const { meta, turboPagesEnabled, entries, entryMap, pageEntries, stubModules, publicPath } = prepare(
Expand Down Expand Up @@ -201,11 +201,12 @@ export default function webpackConfig(api: API, options: Options, target: Platfo
config.plugin('remax-coverage-ignore-plugin').use(RemaxPlugins.CoverageIgnore);

if (typeof options.configWebpack === 'function') {
options.configWebpack({ config });
options.configWebpack({ config, webpack });
}

api.configWebpack({
config,
webpack,
addCSSRule: (ruleConfig: RuleConfig) => {
addCSSRule(config, options, false, ruleConfig);
},
Expand Down
7 changes: 4 additions & 3 deletions packages/remax-cli/src/build/webpack/config.web.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as path from 'path';
import * as fs from 'fs';
import { Configuration } from 'webpack';
import * as webpack from 'webpack';
import Config from 'webpack-chain';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
Expand Down Expand Up @@ -40,7 +40,7 @@ function prepare(options: Options) {
};
}

export default function webpackConfig(api: API, options: Options): Configuration {
export default function webpackConfig(api: API, options: Options): webpack.Configuration {
baseConfig(config, options, Platform.web);

const { entries, appConfig, publicPath } = prepare(options);
Expand Down Expand Up @@ -130,11 +130,12 @@ export default function webpackConfig(api: API, options: Options): Configuration
config.plugin('remax-define-plugin').use(RemaxPlugins.Define, [options, entries]);

if (typeof options.configWebpack === 'function') {
options.configWebpack({ config });
options.configWebpack({ config, webpack });
}

api.configWebpack({
config,
webpack,
addCSSRule: (ruleConfig: RuleConfig) => {
addCSSRule(config, options, false, ruleConfig);
},
Expand Down
2 changes: 1 addition & 1 deletion packages/remax-types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface Options {
rootDir: string;
compressTemplate?: boolean;
UNSAFE_wechatTemplateDepth: number | { [key: string]: number };
configWebpack?: (params: { config: WebpackConfig }) => void;
configWebpack?: (params: { config: WebpackConfig; webpack: any }) => void;
plugins: Plugin[];
one?: boolean;
notify?: boolean;
Expand Down

1 comment on commit 52cb52a

@vercel
Copy link

@vercel vercel bot commented on 52cb52a May 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.