我已经阅读了关于 Webpack 4 将 .scss 文件捆绑到 .css 文件中的所有可能配置。
没有什么对我有用。
这是我的 webpack 配置:
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var absDirPath = __dirname;
module.exports = {
mode: 'development',
entry: [
path.join(absDirPath + '/src/assets/main.scss')
],
output: {
path: path.join(absDirPath + '/dist'),
filename: 'bundle.css',
publicPath: './',
},
plugins: [
new ExtractTextPlugin('bundle.css')
],
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
include: path.join(absDirPath + '/src/assets/*.scss'),
use: ExtractTextPlugin.extract({
use: ['sass-loader', 'css-loader]
})
}
]
}
}
这是我的 .scss 文件:
html, body {
width: 100%;
height: 100%;
}
这是我的 package.json
{
"name": "webpack-sass",
"version": "0.0.1",
"scripts": {
"build": "webpack"
},
"dependencies": {
"css-loader": "^1.0.0",
"extract-text-webpack-plugin": "4.0.0-beta.0",
"mini-css-extract-plugin": "^0.4.1",
"node-sass": "",
"raw-loader": "^0.5.1",
"sass-loader": "^7.1.0",
"style-loader": "^0.22.1",
"webpack": "^4.16.5",
"webpack-cli": "^3.1.0"
}
}
这是我得到的错误
Hash: da6dbe80b661e11c34ed
Version: webpack 4.16.5
Time: 87ms
Built at: 08/14/2018 2:03:36 AM
Asset Size Chunks Chunk Names
bundle.css 4.41 KiB main [emitted] main
Entrypoint main = bundle.css
[./src/assets/main.scss] 185 bytes {main} [built] [failed] [1 error]
[0] multi ./src/assets/main.scss 28 bytes {main} [built]
ERROR in ./src/assets/main.scss 1:11
Module parse failed: Unexpected token (1:11)
You may need an appropriate loader to handle this file type.
> html, body {
| width: 100%;
| height: 100%;
@ multi ./src/assets/main.scss main[0]
npm ERR! Windows_NT 10.0.16299
npm ERR! argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build"
npm ERR! node v6.8.1
npm ERR! npm v3.10.8
npm ERR! code ELIFECYCLE
npm ERR! webpack-sass@0.0.1 build: `webpack`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the webpack-sass@0.0.1 build script 'webpack'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the webpack-sass package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! webpack
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs webpack-sass
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls webpack-sass
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
最重要的是,bundle.css 是一个 js 文件输出为 bundle.css
到目前为止我已经尝试过:
使用样式加载器
使用装载机的组合:
使用:['sass-loader','style-loader','css-loader']
MiniCssExtract插件
在节点 6.8.1 和 8.x 上尝试过
但我得到同样的错误。早些时候,由于加载程序的歧义,我曾经让模块构建失败;这得到了include
关键解决。
自从 4 天以来,我一直在把头撞在墙上。咕噜声更容易。
您能否分享一个工作示例的链接。Github 线程只是人们胡说八道,没有任何工作示例。