Javascript 网页包4不排除节点_模块
我的网页不排除node_modules文件夹,我遵循了此链接 我想从bundle中排除node\u modules文件夹,并尝试了这种较旧的写入方式:exclude:path.resolve(\u dirname,'node\u modules'),但仍然导入了node\u模块 但排除后,控制台中出现错误:Javascript 网页包4不排除节点_模块,javascript,webpack,Javascript,Webpack,我的网页不排除node_modules文件夹,我遵循了此链接 我想从bundle中排除node\u modules文件夹,并尝试了这种较旧的写入方式:exclude:path.resolve(\u dirname,'node\u modules'),但仍然导入了node\u模块 但排除后,控制台中出现错误: Uncaught ReferenceError: require is not defined at Object.<anonymous> (out.fbd501402
Uncaught ReferenceError: require is not defined
at Object.<anonymous> (out.fbd50140277b839fca03.js:1)
at E (out.fbd50140277b839fca03.js:1)
at t (out.fbd50140277b839fca03.js:1)
at Object.<anonymous> (out.fbd50140277b839fca03.js:1)
at Object.<anonymous> (out.fbd50140277b839fca03.js:1)
at E (out.fbd50140277b839fca03.js:1)
at t (out.fbd50140277b839fca03.js:1)
at Object.<anonymous> (out.fbd50140277b839fca03.js:1)
at E (out.fbd50140277b839fca03.js:1)
at out.fbd50140277b839fca03.js:1
已编辑
这是奇怪的,我只是一个网页,但它仍然增加了我超过30个职位!请看下图:
Webpack.config.js
const path = require('path');
module.exports = {
entry: './js/app.js',
output: {
path: path.resolve(__dirname, 'js'),
filename: 'out.js',
},
devServer: {
contentBase: path.resolve(__dirname, 'js'),
port: 3000,
},
module: {
rules: [
{
test: path.resolve(__dirname, 'app.js'),
loader: 'babel-loader',
options: {
presets: ['env'],
},
exclude: path.resolve(__dirname, 'node_modules/')
}
]
}
}
我正在读一本书,我的配置如下:
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
我使用路径解析的唯一位置是输出键
希望这对您有所帮助:)查看您的“目标”配置re:仍然没有。。。我编辑到web,仅当我删除行nodeExternals时,它才工作,但不删除node_modulesray module.rules.exclude使用exclude:path.resolve(uu dirname,“node_modules”),该
node_modules
文件夹与您的网页包配置在同一文件夹中吗?是的,在同一目录中
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},