admin管理员组文章数量:1394156
My webpack doesn't exclude node_modules folder, i followed this link
Webpack not excluding node_modules
I want to exclude node_modules folder from bundle, and have tried this older way to write: exclude: path.resolve(__dirname, 'node_modules') but still node_modules is imported
But after this exclude, I have error in console:
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
And still node_modules folder is imported:
./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./css/style.scss 1.36 KiB {0} [built]
[1] ./node_modules/css-loader/lib/url/escape.js 419 bytes {0} [built]
[2] ./node_modules/css-loader/lib/css-base.js 2.33 KiB {0} [built]
[3] ./images/furry.png 82 bytes {0} [built]
[4] ./images/coin.png 82 bytes {0} [
EDITED
This is weird, I have simply webpack and still it adds me over 30 positions! Look picture below:
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/')
}
]
}
}
My webpack doesn't exclude node_modules folder, i followed this link
Webpack not excluding node_modules
I want to exclude node_modules folder from bundle, and have tried this older way to write: exclude: path.resolve(__dirname, 'node_modules') but still node_modules is imported
But after this exclude, I have error in console:
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
And still node_modules folder is imported:
./node_modules/css-loader!./node_modules/sass-loader/lib/loader.js!./css/style.scss 1.36 KiB {0} [built]
[1] ./node_modules/css-loader/lib/url/escape.js 419 bytes {0} [built]
[2] ./node_modules/css-loader/lib/css-base.js 2.33 KiB {0} [built]
[3] ./images/furry.png 82 bytes {0} [built]
[4] ./images/coin.png 82 bytes {0} [
EDITED
This is weird, I have simply webpack and still it adds me over 30 positions! Look picture below:
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/')
}
]
}
}
Share
Improve this question
edited Sep 20, 2018 at 19:06
Freestyle09
asked Sep 20, 2018 at 16:52
Freestyle09Freestyle09
5,53810 gold badges58 silver badges92 bronze badges
9
- review your 'target' config re: stackoverflow./questions/44351310/… – Robert Rowntree Commented Sep 20, 2018 at 17:00
- Still nothing... i edited to web, only when i remove line nodeExternals it is working but not removing node_modules – Freestyle09 Commented Sep 20, 2018 at 17:09
- retry module.rules.exclude using exclude: path.resolve(__dirname, "node_modules"), – Robert Rowntree Commented Sep 20, 2018 at 17:47
-
Is the
node_modules
folder in the same folder as your Webpack config? – Adam Commented Sep 20, 2018 at 18:17 - Yes, is in the same directory – Freestyle09 Commented Sep 20, 2018 at 18:37
1 Answer
Reset to default 4I'm currently reading a book and my config is set like this:
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
The only place where I use the path.resolve
is on the output key.
Hope this helps :)
本文标签: javascriptWebpack 4 not excluding nodemodulesStack Overflow
版权声明:本文标题:javascript - Webpack 4 not excluding node_modules - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744682875a2619520.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论