【发布时间】:2017-02-01 11:12:50
【问题描述】:
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
./server/test.js
export default function () { console.log(`I’m in the bundle`) } // this is being executed
我在浏览器控制台中看到了消息。
【问题讨论】:
-
Webpack 不能排除您在
index.js中导入和使用的内容 -
exclude和include选项的用途是什么? -
你可以在这里阅读一个很好的解释:stackoverflow.com/questions/37823764/…顺便说一句,你正在测试
.jsx,但你的文件是js -
我正在测试两者,正则表达式中有一个问号。
-
对不起。没看到。
标签: webpack