2016-07-21 79 views
1

我正在嘗試使用webpack構建我的react-redux項目。我有以下行來處理較少的文件:webpack less-loader不工作

{ 
    test: /\.less$/, 
    include: /(stylesheets)/, 
    loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader!less-loader?sourceMap') 
} 

出於某種原因,我收到以下錯誤消息:

ModuleParseError: Module parse failed: C:\path\to\project\client\stylesheets\app.less Unexpected character '@' (1:0) 
You may need an appropriate loader to handle this file type. 
SyntaxError: Unexpected character '@' (1:0) 

任何想法,爲什麼發生這種情況?

*我在Windows 7

回答

0

運行按了 '少裝載機' documentation,你的WebPack想下面......

相應修改您的WebPack配置文件...

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

module.exports = { 
    ... 
    // must be 'source-map' or 'inline-source-map' 
    devtool: 'source-map', 
    module: { 
     loaders: [ 
      { 
       test: /\.less$/, 
       loader: ExtractTextPlugin.extract(
        // activate source maps via loader query 
        'css?sourceMap!' + 
        'less?sourceMap' 
       ) 
      } 
     ] 
    }, 
    plugins: [ 
     // extract inline css into separate 'styles.css' 
     new ExtractTextPlugin('styles.css') 
    ] 
}; 
0

問題在於包含路徑,因爲腳本在Windows上運行。需要在包含字段中給出完整路徑:

{ 
    test: /\.less$/, 
    include: path.join(__dirname, 'stylesheets'), 
    loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader!less-loader?sourceMap') 
}