簡體   English   中英

提取文本Webpack插件編譯錯誤

[英]Extract text Webpack plugin compile error

我正在使用"webpack": "^3.1.0""extract-text-webpack-plugin": "^1.0.1"

嘗試編譯sass時,出現以下錯誤: Error: "extract-text-webpack-plugin" loader is used without the corresponding plugin, refer to https://github.com/webpack/extract-text-webpack-plugin for the usage example

我已經根據提供的文檔使用了它-不明白為什么我會出現webpack構建錯誤。

這是我的webpack文件:

const debug = process.env.NODE_ENV !== "production";
const webpack = require('webpack');
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
  context: path.join(__dirname, "src"),
  devtool: debug ? "inline-sourcemap" : null,
  entry: ['./js/client.js', './styles/base.scss'],
  module: {
    loaders: [
      {
        test: /\.jsx?$/,
        exclude: /(node_modules|bower_components)/,
        loader: 'babel-loader',
        query: {
          presets: ['react', 'es2015', 'stage-0'],
          plugins: ['react-html-attrs', 'transform-class-properties', 'transform-decorators-legacy'],
        }
      }, 
      { 
        test: /\.scss$/,
        use: ExtractTextPlugin.extract({
          fallback: 'style-loader',
          //resolve-url-loader may be chained before sass-loader if necessary
          use: ['css-loader', 'sass-loader']
        })
      }
    ]
  },
  output: {
    path: __dirname + "/src/",
    filename: "client.min.js"
  },
  plugins: debug ? [] : [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({ mangle: false, sourcemap: false }),
    new ExtractTextPlugin('main.css')
  ],
};

您需要包含一些內容來告訴webpack外觀,例如:

 {
    test: /(\.css|\.scss|\.sass)$/,
    include: path.join(__dirname, "../src"), // Include or exclude node modules
    use: ExtractTextPlugin.extract({
      fallback: "style-loader",
      use: ["css-loader", "sass-loader"],
    }),
 },

這是我的webpack.config.babel.js文件,希望對您有所幫助。



    import HtmlWebpackPlugin from 'html-webpack-plugin';
    import ExtractTextPlugin,{extract} from 'extract-text-webpack-plugin';
    import {resolve,join} from 'path';
    // import webpack from 'webpack';

    // var isProd = process.env.NODE_ENV === 'production'; //return true or false
    // var cssDev = [ "style-loader", "css-loader", "sass-loader" ];
    // var cssProd = extract({
    //     fallback: "style-loader",
    //     use: [ "css-loader", "sass-loader"],
    //     publicPath:'/dist'  
    // });
    // var cssConf = isProd ? cssProd : cssDev;


    module.exports = {
        entry: {
            app:'./src/app.js',
        },
        output: {
            path: join(__dirname, "dist"),
            filename : '[name].bundle.js' 
        },
        module: {
            rules:[
                {
                    test: /\.scss$/,
                    exclude: /node_modules/,
                    use: extract({
                        fallback: "style-loader",
                        use: [ "css-loader", "sass-loader"],
                        publicPath:'/dist'  
                    })
                },
                {
                    test: /\.js$/,
                    exclude: /node_modules/,
                    loader: "babel-loader"
                },
                {
                    test: /\.(png|jpg|gif)$/,
                    use:"file-loader",
                }
            ]
        },
        devServer:{
            contentBase: join(__dirname, "dist"),
            compress: true,
            port: 9000,
            stats:'errors-only',
        },
        plugins: [
            new HtmlWebpackPlugin({
                title: 'Webpack starter project',
                template: './src/index.html',
                hash:true,
                excludeChunks: ['contact'],
                minify:{
                    collapseWhitespace: true,
                    minifyCSS: true,
                    minifyJS:true,
                }
            }),
            new ExtractTextPlugin({
                filename: "app.css",
                // disable: !isProd,
                disable: false,            
                allChunks: true
            }),
            // new webpack.HotModuleReplacementPlugin(),
            // new webpack.NamedModulesPlugin(),
        ]
    }

  • 您必須更改提取文本插件的版本

  • 代替新的ExtractTextPlugin('main.css'),使用新的ExtractTextPlugin({文件名:“ main.css”})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM