【问题标题】:Webpack 3 sass loader error after building构建后Webpack 3 sass加载器错误
【发布时间】:2018-01-12 16:48:04
【问题描述】:

我正在使用最新版本的 webpack 3.4.1,使用 sass 加载器和提取文本插件从 sass 源生成静态 css 文件。它在我的开发服务器上加载正常,我可以看到 css 文件,但收到控制台错误“Uncaught SyntaxError: Unexpected token”,它指向第一行的 css 文件@body {color:#000}。

我的 webpack 配置如下。非常感谢任何帮助。

const path = require('path');
const webpack = require('webpack');

const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
  context: path.resolve(__dirname, ''),
  entry: {
    app: './src/js/app.js',
  },
  output: {
    filename: '[name].bundle.js',
    path: path.resolve(__dirname, './dist/assets'),
    publicPath: '/assets',
  },
  devServer: {
    contentBase: path.resolve(__dirname, './src'), // New
  },
  module: {
    rules: [{
        test: /\.js$/,
        exclude: [/node_modules/],
        use: [{
          loader: 'babel-loader',
          options: {
            presets: ['es2015']
          },
        }],
      },
      {
        test: /\.(svg|gif|png|eot|woff|ttf)$/,
        use: [{
          loader: 'url-loader'
        }]
      },
      {
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          use: ['css-loader', 'sass-loader']
        })
      }
    ],
  },
  plugins: [
    new ExtractTextPlugin({
      filename: '[name].bundle.css',
      allChunks: true,
    }),
  ],
};

【问题讨论】:

  • 嗨,克里斯,你解决了吗?
  • 您是否尝试在颜色声明的末尾添加分号? {color:#000;} 从命令行编译 Sass 时我得到了很多,因为 Sass 需要正确的 CSS 语法(与 SCSS 不同)。

标签: webpack sass webpack-dev-server extract-text-plugin extracttextwebpackplugin


【解决方案1】:

为什么你不使用从 Sass 到 CSS 的外部编译器,它对你来说会更快更容易,你只需在 webpack 配置中使用 CSS 加载器, 你有多个从 sass 到 css 的程序编译器,例如(compass,Prepros) Prepros太好了, 我用这种方式,没有任何问题

【讨论】:

    猜你喜欢
    • 2017-01-26
    • 1970-01-01
    • 2019-01-07
    • 2017-12-09
    • 2018-09-12
    • 2016-07-15
    • 2016-02-23
    • 2016-11-20
    • 2019-05-07
    相关资源
    最近更新 更多