如何从 Webpack 捆绑中排除目录? [英] How to exclude directory from getting bundled by Webpack?
问题描述
预期:
当我使用 webpack 构建时,除 ./src/Portfolio 目录中的文件外,我的所有 JS 文件都根据我的 Webpack.config.js 设置进行了捆绑.
When I build with webpack, all my JS files get bundled except for the files in the ./src/Portfolio directory as per my Webpack.config.js settings.
实际:
Webpack 捆绑了所有文件,包括目录中的文件,尽管我在 webpack.config.js 中提供了设置和其他变体.
Webpack bundles all the files including the ones in the directory despite the settings and other variations i have provided within webpack.config.js.
代码:
Webpack.config.js
Webpack.config.js
const path = require('path');
module.exports = {
entry: './src/index.js',
devtool: 'source-map',
mode: 'development',
module: {
rules: [
{
test: /.js$/,
exclude: [
path.resolve(__dirname, './src/Portfolio/')
]
}
]
},
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist')
}
};
输出:
如何成功排除 ./src/Portfolio 目录及其内容?
How can i successfully exclude the ./src/Portfolio directory and its contents?
推荐答案
根据您的文件夹结构,看起来您没有为其提供正确的目录位置以排除.我认为这样的事情应该可行,但如果不行,请分享您的文件夹结构.
Depending on what your folder structure looks like it appears you aren't providing it the right directory location to exclude. I would think something like this should work, but if not please share your folder structure.
const path = require('path');
module.exports = {
entry: './src/index.js',
devtool: 'source-map',
mode: 'development',
module: {
rules: [
{
test: /.js$/,
exclude: [
'./src/Portfolio/'
]
}
]
},
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist')
}
};
这篇关于如何从 Webpack 捆绑中排除目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!