不必要的大括号

时间:2018-05-27 11:28:37

标签: javascript webpack sass sass-loader

我正在尝试使用postpackader和webpack 4,如下所示:

   test: /\.s?[ac]ss$/,
    use: [
      {
        loader: "css-loader"
      },
      {
        loader: "postcss-loader"
      },
      {
        loader: "sass-loader",
        options: {
          sourceMap: true,
          includePaths: ["node_modules", "node_modules/@material/*"].map(
            d => path.join(__dirname, d)
          )
        }
      }
    ]
  },

由于https://github.com/material-components/material-components-web

,我必须加入node_modules

index.scss文件:

@import "./Topbar/scss/topbar.scss";
@import "./Sidebar/scss/sidebar.scss";

body {
  margin: 0;
  padding: 0;
}

编译器抱怨:

ERROR in ./src/index.scss
Module build failed: Syntax Error

(1:6) Unnecessary curly bracket

> 1 | body {
    |      ^
  2 |   margin: 0;
  3 |   padding: 0; } 

我做错了什么?

更新
我从test: /\.s?[ac]ss$/更改为test: /\.scss$/index.scss的内容保持不变:

body {
  margin: 0;
  padding: 0;
}

编译器仍抱怨:

    ERROR in ./src/index.scss (./node_modules/css-loader!./node_modules/postcss-loader/lib!./node_modules/sass-loader/lib/loader.js??ref--6-3!./src/index.scss)
    Module build failed: Syntax Error

    (1:6) Unnecessary curly bracket

    > 1 | body {
        |      ^
      2 |   margin: 0;
      3 |   padding: 0; }

ℹ 「wdm」: Failed to compile.

更新2

这就是整个配置:

const HtmlWebPackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const path = require("path");
const glob = require("glob");


module.exports = {
  entry: ["./src/index.js"],
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "bundle.[hash].js"
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader",
          options: {
            presets: ["@babel/preset-env", "@babel/preset-react"]
          }
        }
      },
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader",
            options: {
              minimize: true
            }
          }
        ]
      },
      {
        test: /\.scss$/,
        use: [
          {
            loader: MiniCssExtractPlugin.loader
          },
          {
            loader: "css-loader"
          },
          /*{
            loader: "postcss-loader"
          },*/
          {
            loader: "sass-loader",
            options: {
              sourceMap: true,
              includePaths: ["node_modules", "node_modules/@material/*", "src"].map(
                d => path.join(__dirname, d)
              )
            }
          }
        ]
      },
      {
        test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
        use: [
          {
            loader: "file-loader",
            options: {
              name: "[name][hash].[ext]",
              outputPath: "fonts/"
            }
          }
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: "./public/index.html",
      filename: "./index.html"
    }),
    new CopyWebpackPlugin([
      {
        from: "public"
      }
    ])
  ]
};

0 个答案:

没有答案