Webpack 2 sass-loader 意外字符'@'

Webpack 2 sass-loader Unexpected character '@'

当 运行 webpack 抛出下一个错误时,我有下一个 webpack 2 规则配置:

Unexpected character '@' (1:0)
You may need an appropriate loader to handle this file type.
| @media screen and (min-width: 40em) {
|   .feature {
|     margin-bottom: 8.75rem;
 @ ./~/style-loader?{"camelCase":true,"localIdentName":"[name]_[local]_[hash:base64:3]","modules":true}!./~/postcss-loader!./~/resolve-url-loader!./~/sass-loader?{"sourceMap":true,"outputStyle":"expanded","include":["/opt/inmoblex/current/inmoblex/cfg/src/styles","node_modules"]}!./src/components/LandingFeature/styles.scss 4:14-310

有什么问题吗?

:)

感谢帮助

rules: [
  {
    test: /\.css$/,
    use: [
      { loader: 'isomorphic-style-loader' },
      { loader: 'css-loader' },
      { loader: 'postcss-loader' },
    ]
  },
  {
    test: /\.scss/,
    use: [
      { loader: 'isomorphic-style-loader' },
      {
        loader: 'style-loader',
        options: {
          camelCase: true,
          localIdentName: '[name]_[local]_[hash:base64:3]',
          modules: true
        }
      },
      { loader: 'postcss-loader' },
      { loader: 'resolve-url-loader' },
      {
        loader: 'sass-loader',
        options: {
          sourceMap: true,
          outputStyle: 'expanded',
          include: [
            path.resolve(__dirname, "./src/styles"),
            "node_modules",
          ],
        }
      },
    ]
  },
  {
    test: /\.json/,
    use: [
      { loader: 'json-loader' },
    ]
  },
  {
    test: /\.(png|jpg|gif|woff|woff2)$/,
    use: [{
      loader: 'url-loader',
    }]
  },
  {
    test: /\.(mp4|ogg|svg)$/,
    use: [{
      loader: 'file-loader',
    }]
  },
],

在使用 sass-loaderresolve-url-loaderpostcss-loader 处理 .scss 之后,您正在使用 style-loader。结果仍然是 CSS,所以应该有一个 css-loader 将它转换为 JavaScript。因为您正在使用 isomorphic-style-loader,所以您不需要 style-loader,并且从您传递给它的选项来看,它看起来应该是 css-loader。所以将 style-loader 重命名为 css-loader:

{
  test: /\.scss/,
  use: [
    { loader: 'isomorphic-style-loader' },
    {
      loader: 'css-loader',
      options: {
        camelCase: true,
        localIdentName: '[name]_[local]_[hash:base64:3]',
        modules: true
      }
    },
    { loader: 'postcss-loader' },
    { loader: 'resolve-url-loader' },
    {
      loader: 'sass-loader',
      options: {
        sourceMap: true,
        outputStyle: 'expanded',
        include: [
          path.resolve(__dirname, "./src/styles"),
          "node_modules",
        ],
      }
    },
  ]
},