gpt4 book ai didi

webpack - 包含/排除不起作用

转载 作者:行者123 更新时间:2023-12-02 01:17:29 26 4
gpt4 key购买 nike

网络包 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

我在浏览器控制台中看到了消息。

最佳答案

答案是如果你 include/exclude webpack 配置中的某些内容不会被加载程序转换,但会被导入到包中。要从捆绑中完全排除某些内容,您需要使用 module.noParse选项:https://webpack.js.org/configuration/module/#module-noparse

关于webpack - 包含/排除不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41978343/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com