I want to override the exclude / include of a webpack rule. The project has been created with vue-cli-sevice
and therefore only has a vue.config.js
. I am able to hook into the configuration with chainWebpack
, but I'm not able to edit the rule itself.
The output of vue-cli-service inspect
contains the rule I want to edit:
/* config.module.rule('js') */
{
test: /\.jsx?$/,
exclude: [
function () { /* omitted long function */ }
],
use: [
{
loader: 'cache-loader',
options: {
cacheDirectory: '/Users/m/projects/echo/.../.cache/babel-loader',
cacheIdentifier: '4b5cee3d'
}
},
{
loader: 'babel-loader'
}
]
},
I now want to edit this configuration from my vue.config.js
(the commented out part shows how I found it in the documentation but it's not working):
const chainWebpack = (config) => {
config.module.rule('js');
// .include
// .add('node-modules/blubb')
// .end();
};
module.exports = {
chainWebpack
};
How can I add an include
or override the exclude
property of this rule configuration?
I got it working like so. This clears the whole exclude and adds an include.
The easiest way to check if everything works as expected is IMO to run
vue-cli-service inspect
. Change the config, check if inspect fails and, if it doesn't, check if the output contains the desired changes.