【问题标题】:Structure for using Grunt and Webpack使用 Grunt 和 Webpack 的结构
【发布时间】:2016-01-14 13:25:12
【问题描述】:

我有这样一个典型的 Webpack 设置:

// webpack.config.js    
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    entry: "./entry.js",
    output: {
        path: "./build",
        filename: "bundle.js"
    },
    module: {
        loaders: [
                { test: /\.scss$/, loader: ExtractTextPlugin.extract('css!sass')
            }
        ]
    },
    plugins: [
        new ExtractTextPlugin('style.css', {
            allChunks: true
        })
    ]
};

但我仍然想使用 Grunt 来运行我的构建,所以我尝试从 Grunt 任务中调用 Webpack,因此将所有设置移到 Grunt 中,如下所示:

// webpack.js - This is a grunt task being loaded into gruntfile.js    
module.exports = {
    entry: "./entry.js",
    output: {
        path: "./build",
        filename: "bundle.js"
    },
    module: {
        loaders: [
                { test: /\.scss$/, loader: ExtractTextPlugin.extract('css!sass') }
        ]
    },
    plugins: [
        new ExtractTextPlugin('style.css', {
            allChunks: true
        })
    ]
    };

现在明显的问题是,当我运行 grunt build 时,它无法识别对 ExtractTextPlugin 的引用。那么,既然我不能使用 webpack.config,我该在哪里声明呢?

如果我做错了,请告诉我,因为我刚刚学习 Webpack。

【问题讨论】:

    标签: javascript sass gruntjs webpack


    【解决方案1】:

    你只需要自己要求它:

    var ExtractTextPlugin = require("extract-text-webpack-plugin");
    

    【讨论】:

      猜你喜欢
      • 2015-05-31
      • 1970-01-01
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-16
      • 1970-01-01
      相关资源
      最近更新 更多