Webpack 2.2.0
我在配置中包含/排除文件/文件夹,但webpack保留了被排除的捆绑:
文件夹结构
src/
index.js // entry point
server/
test.js // file for testing
build/
webpack.config.js
const path = require('path')
const SRC = path.resolve(process.cwd(), './src')
const BUILD = path.resolve(process.cwd(), './build')
module.exports = {
context: SRC,
entry: {
main: './'
},
output: {
path: BUILD,
filename: '[name].bundle.js',
publicPath: '/assets/'
},
module: {
rules: [{
test: /\.jsx?/,
include: SRC,
exclude: path.resolve(process.cwd(), './server’), // even explicit excluding changes nothing
loader: 'babel-loader'
}]
}
}
./ SRC / index.js
import func from ‘../server/test.js’ // this must not be imported
func() // working
./服务器/ test.js
export default function () { console.log(`I’m in the bundle`) } // this is being executed
我在浏览器控制台中看到了该消息。
答案 0 :(得分:1)
答案是,如果您在webpack配置中include/exclude
某些东西,它将不会被加载器转换,但它将被导入到捆绑包中。要从捆绑中完全排除某些内容,您需要使用module.noParse
选项:https://webpack.js.org/configuration/module/#module-noparse