-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
提供更灵活的 Webpack 扩展方法 #76
Labels
Comments
Merged
增加了
// 使用 extend 方法直接修改 webpack 配置对象
config.module.rules[0].use[0].options.loader 而使用 // 扩展 babel
config.module
.rule('js')
.use('babel')
.tap(options => merge(options, { plugins: ['babel-plugin-syntax-object-rest-spread'] }));
extendWithWebpackChain: (config) => {
// 每个插件都可以按名称访问
config.plugin('friendly-error').init((Plugin, args) => {
let customParams = {}; // 扩展传入插件构造函数的参数
return new Plugin(...args, customParams)
});
} |
稍后会在文档中详细列出 Lavas 内部使用的全部 Webpack 插件和 Loader,便于开发者便捷引用修改。 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题描述
目前 Lavas 提供了 extend 方法用于扩展内置的 Webpack 配置对象。这种方式直接暴露原始的 Webpack 配置对象给开发者,在增加 loader/plugin 这样的场景下,还能通过如下方式进行:
但是一旦涉及到修改 Lavas 内置的某些配置,例如针对 vue-loader 的配置,就很不优雅了。常常只能在控制台将整个对象打印出来,才能定位到需要修改的某个 loader/plugin。
解决方案
看来核心问题是仅仅暴露给开发者一个对象,不利于修改 Lavas 已有的配置。而且无法对内置的 plugin/loader 取名供开发者便捷地引用修改。
参考 poi,使用了 webpack-chain 对 Webpack 配置对象进行了封装,使得开发者可以使用链式调用的方式修改,同时可以对 plugin/loader 规则 取自定义的名字,更加便于开发者修改:
所以在保留已有
extend()
方法的基础上,可以新增一个针对这种方式的扩展方法extendWithWebpackChain()
:The text was updated successfully, but these errors were encountered: