Webpack@4.0.0: "Module parse failed. You may need an appropriate loader to handle this file type" - 尽管使用 css-loader 和 style-loader
Webpack@4.0.0: "Module parse failed. You may need an appropriate loader to handle this file type" - though using css-loader and style-loader
下面是我的webpack.config.js和package.json
module.exports = {
entry: "./entry.js",
output: {
filename: "./build/js/bundle.js"
},
module: {
rules: [
{
test: /.\js$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ["es2015"]
}
}
]
},
{
test: /.\css?$/,
include: __dirname + "./src/css",
exclude: __dirname + "./src/js",
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true
}
}
]
}
]
},
plugins: [
// new UglifyJsPlugin()
]
}
"dependencies": {
"ajv-keywords": "^3.1.0",
"ajv": "^6.0.0",
"axios": "^0.17.1",
"babel-minify-webpack-plugin": "^0.3.0",
"extract-text-webpack-plugin": "^3.0.2",
"install": "^0.10.4",
"npm": "^5.6.0"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.3",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^0.28.10",
"style-loader": "^0.20.2",
"webpack": "^4.0.0"
},
错误如下
ERROR in ./src/css/autosuggest-style.css Module parse failed:
Unexpected token (1:0) You may need an appropriate loader to handle
this file type. | .ngCustomInput *, *:before, *:after { |
-moz-box-sizing: border-box; | -webkit-box-sizing: border-box; @ ./entry.js 20:0-42
ERROR in ./src/css/newUiStyles.css Module parse failed: Unexpected
token (1:4) You may need an appropriate loader to handle this file
type. | body{ | background-color: #F2F2F2; | font-family:
sans-serif; @ ./entry.js 3:0-36 ERROR in
./src/css/custom-style.css Module parse failed: Unexpected token (2:0)
You may need an appropriate loader to handle this file type. | /*
Styles go here */ | .border | { | border:1px solid transparent; @
./entry.js 21:0-37
不确定是什么错误....
在此先感谢您的帮助
请查看您的正则表达式以进行匹配。这是错误的。
应该是:
/\.css$/
对于 css
/\.js$/
对于 js
您的反斜杠位置错误。
您的正则表达式匹配名为:style\css
的文件
下面是我的webpack.config.js和package.json
module.exports = {
entry: "./entry.js",
output: {
filename: "./build/js/bundle.js"
},
module: {
rules: [
{
test: /.\js$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ["es2015"]
}
}
]
},
{
test: /.\css?$/,
include: __dirname + "./src/css",
exclude: __dirname + "./src/js",
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true
}
}
]
}
]
},
plugins: [
// new UglifyJsPlugin()
]
}
"dependencies": {
"ajv-keywords": "^3.1.0",
"ajv": "^6.0.0",
"axios": "^0.17.1",
"babel-minify-webpack-plugin": "^0.3.0",
"extract-text-webpack-plugin": "^3.0.2",
"install": "^0.10.4",
"npm": "^5.6.0"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.3",
"babel-preset-es2015": "^6.24.1",
"css-loader": "^0.28.10",
"style-loader": "^0.20.2",
"webpack": "^4.0.0"
},
错误如下
ERROR in ./src/css/autosuggest-style.css Module parse failed: Unexpected token (1:0) You may need an appropriate loader to handle this file type. | .ngCustomInput *, *:before, *:after { |
-moz-box-sizing: border-box; | -webkit-box-sizing: border-box; @ ./entry.js 20:0-42ERROR in ./src/css/newUiStyles.css Module parse failed: Unexpected token (1:4) You may need an appropriate loader to handle this file type. | body{ | background-color: #F2F2F2; | font-family: sans-serif; @ ./entry.js 3:0-36 ERROR in ./src/css/custom-style.css Module parse failed: Unexpected token (2:0) You may need an appropriate loader to handle this file type. | /* Styles go here */ | .border | { | border:1px solid transparent; @ ./entry.js 21:0-37
不确定是什么错误....
在此先感谢您的帮助
请查看您的正则表达式以进行匹配。这是错误的。 应该是:
/\.css$/
对于 css
/\.js$/
对于 js
您的反斜杠位置错误。 您的正则表达式匹配名为:style\css
的文件