【发布时间】:2018-09-12 10:20:25
【问题描述】:
在我的 javascript 项目的一个非常简单的演示中,我使用“css-loader”来加载 css 文件。
package.json
{
"devDependencies": {
"webpack": "^4.17.1",
"webpack-cli": "^3.1.0",
"css-loader": "^1.0.0",
"style-loader": "^0.23.0"
}
}
webpack.config.js
const path = require('path')
module.exports = {
mode: 'development',
entry: './entry.js',
output: {
path: __dirname,
filename: 'bundle.js'
},
module: {
rules: [{
test: /\.css$/,
exclude: path.resolve('./node_modules/'),
use: [
{loader: 'style-loader'},
{loader: 'css-loader'}
]
}]
}
}
请注意我已经排除了“node_modules”目录。
但是当我运行npx webpack 时,输出
Hash: 3d4b3f13f73f8b4ff12f
Version: webpack 4.17.1
Time: 255ms
Built at: 2018-09-12 18:13:34
Asset Size Chunks Chunk Names
bundle.js 23 KiB main [emitted] main
Entrypoint main = bundle.js
[./entry.js] 78 bytes {main} [built]
[./index.css] 1.04 KiB {main} [built]
[./node_modules/css-loader/index.js!./index.css] ./node_modules/css-loader!./index.css 196 bytes {main} [built]
+ 3 hidden modules
仍然包含一些关于“node_modules”的内容。
我找不到问题出在哪里,如何解决?
更新:
我为这个问题做了一个演示:https://github.com/freewind-demos/javascript-webpack-exclude-node-modules-issue-demo ,您可以克隆并尝试使用它。
【问题讨论】:
标签: javascript css webpack