3

我有這個裝載機在我的WebPack裝載機陣列:元素從裝載機名單應該有「裝載機」或「裝載機」與上海社會科學院裝載機的WebPack

{ test: /\.scss$/, exclude: /node_modules/, loaders: ExtractTextPlugin('style-loader', 'css-loader!sass-loader') } 

我想有的WebPack建立我SCSS到CSS,但我收到此錯誤:

/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/webpack-core/lib/LoadersList.js:60 
    throw new Error("Element from loaders list should have one of the fields 'loader' or 'loaders'"); 
    ^

Error: Element from loaders list should have one of the fields 'loader' or 'loaders' 
    at getLoadersFromObject (/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/webpack-core/lib/LoadersList.js:60:8) 
    at LoadersList.<anonymous> (/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/webpack-core/lib/LoadersList.js:78:12) 
    at Array.map (native) 
    at LoadersList.match (/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/webpack-core/lib/LoadersList.js:70:19) 
    at NormalModuleFactory.<anonymous> (/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/lib/NormalModuleFactory.js:109:65) 
    at /Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/async/lib/async.js:697:13 
    at /Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/async/lib/async.js:52:16 
    at done (/Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/async/lib/async.js:248:21) 
    at /Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/async/lib/async.js:44:16 
    at /Users/bli1/Development/Django/CL/cherngloong/cherngloong/cherngloong/node_modules/webpack/node_modules/async/lib/async.js:694:17 

這裏是我的全部的WebPack配置:

var path = require('path'); 
var webpack = require('webpack'); 
var BundleTracker = require('webpack-bundle-tracker'); 
var ExtractTextPlugin = require("extract-text-webpack-plugin"); 

module.exports = { 
    entry: [ 
    './app/index' 
    ], 

    output: { 
     path: path.resolve('./public/bundles/'), 
     filename: "[name]-[hash].js", 
    }, 

    plugins: [ 
    new BundleTracker({filename: './webpack-stats.json'}), 
    ], 

    module: { 
    loaders: [ 
     { test: /\.css$/, exclude: /node_modules/, loader: 'style!css' }, 
     { test: /\.json$/, loader: 'json-loader' }, 
     { test: /\.jsx$/, loaders: ['react-hot', 'babel-loader'], include: path.join(__dirname, 'app') }, 
     { test: /\.es6$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'}, 
     { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader?stage=0&optional=runtime'}, 
     { test: /\.scss$/, exclude: /node_modules/, loaders: ExtractTextPlugin('style-loader', 'css-loader!sass-loader') } 
    ] 
    }, 
} 

回答

4

Sokra提供的h的例子ow在這裏使用ExtractTextPlugin:https://github.com/webpack/extract-text-webpack-plugin/blob/master/example/webpack.config.js

正如你所看到的,你的例子和他的例子有一些區別。

  • 的ExtractTextPlugin構造函數被調用與內側「插件:[]」陣列
  • 插件在裝載機陣列是通過調用靜態方法.extract(所使用的方式),而不是簡單地呼籲插件構造
  • 在「加載器對象」的提法是「loade R:」屬性,而不是「loade RS:」因爲你已經把(裝載機是一種選擇,但預計數組)

希望有幫助!

+2

我沒有看到'extract()'我太累了。謝謝!我需要另一雙眼睛! – Liondancer

+0

沒問題,樂意幫忙 –

+0

我遇到了更多的問題= [如果你想對他們開槍,我會很感激謝謝! [here](http://stackoverflow.com/questions/33328898/404-because-of-restarting-the-webpack-dev-server)和[here](http://stackoverflow.com/questions/33324553/babel -trying到負荷較少的風格,與-的WebPack) – Liondancer