【问题标题】:How to use react-widgets-webpack with extract-text-webpack-plugin for Webpack 2如何将 react-widgets-webpack 与 extract-text-webpack-plugin 一起用于 Webpack 2
【发布时间】:2017-03-07 20:33:33
【问题描述】:

当我尝试关注 instructions 使用 react-widgets-webpack 时 extract-text-webpack-plugin 和 Webpack 2,我收到以下错误:

错误 ./~/react-widgets-webpack/index.loader.js!./react-widgets.config.js 模块构建失败:错误:重大更改:现在提取只需要 单论。一个选项对象加载器。例子: 如果您的旧代码如下所示: ExtractTextPlugin.extract('style-loader', 'css-loader')

您可以将其更改为: ExtractTextPlugin.extract({ fallback: 'style-loader', use: 'css-loader' })

改成

styleLoader: require('extract-text-webpack-plugin').extract({
        fallback: "style-loader",
        use: 'css-loader!less-loader'
    })

给出以下错误:

错误 ./~/react-widgets-webpack/index.loader.js!./react-widgets.config.js 找不到模块:错误:无法解析'[object Object],[object 对象],[对象对象],[对象对象]'在 '/Users/pbirmingham/Development/FLA/forks/flash/flash'

我的 webpack.config.js:

const webpack = require('webpack');
const globalizePlugin = require('globalize-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
    entry: {
        app: [
            'react-widgets-webpack!./react-widgets.config.js',
            'bootstrap-loader',
            './js/main.js']
    },
    output: {
        path: './public/',
        filename: 'js/bundle-[hash].js',
    },
    module: {
        rules: [
            {test: /\.(js|jsx)$/, exclude: /node_modules/, use: 'babel-loader'},
            {test: /\.json$/, use: 'json-loader'},
            {
                test: /\.(css|scss)$/,
                use: ExtractTextPlugin.extract({
                    fallback: "style-loader",
                    use: ['css-loader', 'sass-loader']
                })
            },
            {
                test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
                use: "url-loader?name=[name].[hash].[ext]&limit=10000&mimetype=application/font-woff"
            },
            {test: /\.(ttf|eot|svg|gif)$/, use: "file-loader?name=[name].[hash].[ext]"},
            {test: /bootstrap.+\.(jsx|js)$/, use: 'imports-loader?jQuery=jquery,$=jquery,this=>window'}
        ]
    },
    plugins: [
        new ExtractTextPlugin({ filename: 'css/main.[contenthash].css'}),
        new globalizePlugin({
            production: false,
            developmentLocale: "en",
            supportedLocales: ["en"],
            output: "globalize-compiled-data-[locale].[hash].js"
        }),
        new HtmlWebpackPlugin({
            template: 'template/index.ejs',
            chunks: ['app']
        }),
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: JSON.stringify('production')
            }
        })
    ]
}

还有其他人看到过这种行为吗?

【问题讨论】:

    标签: javascript webpack-2 extracttextwebpackplugin


    【解决方案1】:

    我遇到了同样的问题。 在 package.json 中设置 "extract-text-webpack-plugin": "~0.8.0" 然后定义 ExtractTextPlugin 加载器,如 loader: ExtractTextPlugin.extract('style', 'css!less')

    【讨论】:

      猜你喜欢
      • 2017-07-11
      • 2016-03-11
      • 2016-03-04
      • 2017-03-08
      • 2018-01-26
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 2018-03-03
      相关资源
      最近更新 更多