Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
599 views
in Technique[技术] by (71.8m points)

javascript - Webpack无法编译sass-模块解析失败:意外字符'@'(1:0)(Webpack can't compile sass - Module parse failed: Unexpected character '@' (1:0))

I'm trying to use webpack for the first time and I would like to use SASS instead of CSS but I can't resolve a problem with my sass-loader.

(我第一次尝试使用webpack,但我想使用SASS而不是CSS,但是我无法解决sass-loader的问题。)

my webpack.common.js:

(我的webpack.common.js:)

 const path = require('path'); module.exports = { entry: './src/index.js', output: { filename: 'js/main.js', path: path.resolve(__dirname, 'dist') }, module: { rules: [ { test: /\.(css|scss)$/, use: ['style-loader', 'css-loader', { loader: 'postcss-loader', options: { ident: 'postcss', plugins: [ require('autoprefixer')() ] } }, 'sass-loader'] }, { test: /\.(jpg|jpeg|gif|png)$/, use: [ { loader: 'url-loader', options: { limit: 102400, name: '[name].[ext]', outputPath: 'images' } } ] }, { test: /\.(woff(2)?|ttf|eof|svg)$/, use: [ { loader: 'file-loader', options: { name: '[name].[ext]', outputPath: 'fonts' } } ] }, { test: /\.js$/, exclude: /node_modules/, use: [ { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } } ] } ] } } 

I've already install sass-loader and node-sass package with npm and I load my webpack.common.js file in a webpack.dev.js file :

(我已经安装青菜装载机节点青菜包NPM和我加载我webpack.common.js文件中webpack.dev.js文件:)

 const merge = require('webpack-merge'); const common = require('./webpack.common'); const path = require('path'); module.exports = merge(common, { mode: 'development', devServer: { port: 3000, contentBase: path.join(__dirname, 'dist'), watchOptions: { ignored: /node_modules/ } } }); 

Honestly I don't think the problem is caused by this file.

(老实说,我不认为问题是由该文件引起的。)

To run my app I use npm run dev .

(要运行我的应用程序,请使用npm run dev 。)

Atleast, there is my sass file (in src/styles/styles.scss):

(至少,有我的sass文件(在src / styles / styles.scss中):)

 @import '~bootstrap/scss/bootstrap.scss'; @import '~@fortawesome/fontawesome-free/css/all.css'; body { background-color: #eee; } 

Do you know how can I resolve this problem ?

(您知道如何解决此问题吗?)

I know this question was asked a lot of time, I searched on github and stackoverflow before post but I didn't succeed to make my app work.

(我知道这个问题被问了很多次,我在发布之前在github和stackoverflow上进行了搜索,但是我没有成功使我的应用程序正常运行。)

Thank you in advance.

(先感谢您。)

  ask by Yacine Chalabi translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...