v4 代码迁移:更新 webpack 配置
¥v4 code migration: Updating the webpack configuration
本指南是 v4 代码迁移指南 的一部分,旨在帮助你将 Strapi 应用的代码从 v3.6.x 迁移到 v4.0.x
¥This guide is part of the v4 code migration guide designed to help you migrate the code of a Strapi application from v3.6.x to v4.0.x
在 Strapi v3 和 v4 中,webpack 配置都是可定制的。
¥In both Strapi v3 and v4, the webpack configuration is customizable.
在 Strapi v4 中,使用了 Webpack v5,webpack 开发服务器仅监视 ./src/admin/app.js
和 ./src/admin/extensions
文件夹下的文件(请参阅 管理面板定制 文档)。
¥In Strapi v4, webpack v5 is used, and only ./src/admin/app.js
and the files under the ./src/admin/extensions
folder are being watched by the webpack dev server (see admin panel customization documentation).
在迁移之前确保 webpack 插件和加载器已升级到最新版本。
¥Make sure webpack plugins and loaders are upgraded to the latest version before migrating.
要将 webpack 配置更新到 Strapi v4:
¥To update the webpack configuration to Strapi v4:
将
./src/admin/webpack.config.example.js
重命名为./src/admin/webpack.config.js
。¥Rename the
./src/admin/webpack.config.example.js
to./src/admin/webpack.config.js
.将
./admin/admin.config.js
的内容从 Strapi v3 应用复制到./src/admin/webpack.config.js
。¥Copy the content of
./admin/admin.config.js
from the Strapi v3 application to./src/admin/webpack.config.js
.
Example of a webpack configuration file in Strapi v4:
'use strict';
// WARNING: the admin panel now uses webpack 5 to bundle the application.
module.exports = (config, webpack) => {
// Note: we provide webpack above so you should not `require` it
// Perform customizations to webpack configuration
config.plugins.push(new webpack.IgnorePlugin(/\/__tests__\//));
// Important: return the modified configuration
return config;
};