跳至主要内容

Webpack

craco.config.js
module.exports = {
// ...
webpack: {
alias: { /* ... */ },
plugins: {
add: [ /* ... */ ],
remove: [ /* ... */ ],
},
configure: { /* ... */},
configure: (webpackConfig, { env, paths }) => {
/* ... */
return webpackConfig;
},
},
};
提示

上面列出的轮廓中的属性重复出现(例如 configure)可以被分配一个对象文字或一个函数。有关详情,请参阅配置提示

webpack.alias

对象

参见 https://webpack.js.cn/configuration/resolve/#resolvealias

webpack.plugins

webpack.plugins.add

[WebpackPlugin | [WebpackPlugin, 'append' | 'prepend']]

待添加的 Webpack 插件数组: https://webpack.js.cn/plugins/

你可以指定每个插件是要追加到现有的 Webpack 插件列表还是前置到现有的 Webpack 插件列表。如果未指定,则默认为前置。查看以下示例

craco.config.js
const CopyPlugin = require('copy-webpack-plugin');
const ESLintPlugin = require('eslint-webpack-plugin');
const HtmlPlugin = require('html-webpack-plugin');

module.exports = {
webpack: {
plugins: {
add: [
new CopyPlugin() /* this plugin will be prepended */,
[new ESLintPlugin(), 'prepend'] /* this one, too */,
[new HtmlPlugin(), 'append'] /* not this one though */,
],
},
},
};

webpack.plugins.remove

[string]

待删除的插件构造函数名称数组。

webpack.configure

WebpackConfig(config: WebpackConfig, { env, paths }) => WebpackConfig

所有 Webpack 配置选项:https://webpack.js.cn/configuration/