【问题标题】:module parse failed after adding the sass loaders添加 sass 加载器后模块解析失败
【发布时间】:2020-08-16 19:22:36
【问题描述】:

我正在学习关于 webpack 的初学者教程,我应该在我的项目中使用 sass,所以我运行了这个命令 npm i -D style-loader node-sass css-loader sass-loader 来安装我需要的必要加载器。另外,我在我的规则数组{ test: /\.scss$/, use: [ 'style-loader', 'css-loader', 'sass-loader' ] }中添加了一个测试用例。我试图运行我的应用程序,它给了我一个我没有得到的 sass 错误

我的 package.json

我的 webpack.dev.js

// Allows us to override the default configs that comes with webpack
const path = require("path")
const webpack = require('webpack')
const HtmlWebPackPlugin = require("html-webpack-plugin")
const { CleanWebpackPlugin } = require('clean-webpack-plugin');

module.exports = {
  mode:'development',
  stats: 'verbose',
  entry: './src/client/index.js',
  module: {
    rules: [
    {
        test:'/\.js$/',
        exclude:/node_modules/,
        loader:"babel-loader"

    },
    {
      test: '/\scss$/',
      use: [ 'style-loader', 'css-loader', 'sass-loader' ]
    }
    ]
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: "./src/client/views/index.html",
      filename: "./index.html"
    }),
    new CleanWebpackPlugin({
            // Simulate the removal of files
            dry: true,
            // Write Logs to Console
            verbose: true,
            // Automatically remove all unused webpack assets on rebuild
            cleanStaleWebpackAssets: true,
            protectWebpackAssets: false
        })
  ]
};

我在这里错过了什么?

【问题讨论】:

    标签: node.js webpack sass frontend


    【解决方案1】:

    你是不是在加载器的正则表达式(测试)属性中遗漏了一个点? /\.scss/

    在 webpack.dev.js 中

    【讨论】:

    • 成功了,谢谢。我发现 $ 需要编辑。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-02
    • 1970-01-01
    • 2019-10-24
    • 2017-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多