2016-07-30 28 views
2

我想写一个webpack文件,将在esj支持reactjs中创建一个项目。这里是我的webpack.config.js你可能需要一个合适的加载器来加载这个文件在webpack不在Linux和Mac OS的窗口

webpackConfig = { 
    /*entry: './index.js', 
    output: { 
     path: path.resolve(__dirname, 'dist/'), 
     filename: 'build.js' 
    },*/ 
    entry: { 
     lite: "./lite.js", pro: "./pro.js", 
    }, 
    output: { filename: "dist/[name].js" }, 
    plugins: [ 
     new webpack.optimize.CommonsChunkPlugin("dist/init.js"), 
     new WebpackNotifierPlugin({alwaysNotify: true, title: 'Webpack'}) 
    ], 
    module: { 
     loaders: [ 
      { 
       test: /\.(js|jsx)$/, 
       exclude: /node_modules/, 
       include: __dirname + '/src', 
       loader: 'babel-loader', 
       query: { 
        presets: ['react','es2015'] 
       } 
      }, 
      { 
       test: /\.css$/, 
       loader: ExtractTextPlugin.extract('style-loader', 'css-loader?modules') 
      }, 
      { 
       test: /\.html$/, 
       loader: 'html-loader' 
      }, 
      { 
       test: /\.less$/, 
       loader: "style!css!less" 
      }, 
      { 
       test: /\.(jpe?g|png|gif|svg)$/i, 
       loaders: [ 
        'file?hash=sha512&digest=hex&name=[hash].[ext]', 
        'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false' 
       ] 
      } 
      // { test: /\.css$/, loader: "style-loader!css-loader" }, 
     ] 
    } 
}; 

这里是我的.babelrc文件

{ 
    "presets" : ["es2015", "react"] 
} 

它运行在Mac OS和Linux,但有一个问题,当我尝试在Windows中运行它。对该错误的任何解释?真奇怪。

以下是错误

ERROR in ./src/lite.js 
Module parse failed: C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\plugins\cf7s       kins-visual\src\lite.js Unexpected token (9:12) 
You may need an appropriate loader to handle this file type. 
SyntaxError: Unexpected token (9:12) 
    at Parser.pp$4.raise (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\plugins       \cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15) 
    at Parser.pp.unexpected (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\plug       ins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10) 
    at Parser.pp$3.parseExprAtom (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content       \plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1822:12) 
    at Parser.pp$3.parseExprSubscripts (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-c       ontent\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:17       15:21) 
    at Parser.pp$3.parseMaybeUnary (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-conte       nt\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1692:1       9) 
    at Parser.pp$3.parseExprOps (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\       plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1637:21) 
    at Parser.pp$3.parseMaybeConditional (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp       -content\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:       1620:21) 
    at Parser.pp$3.parseMaybeAssign (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-cont       ent\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1597:       21) 
    at Parser.pp$3.parseParenAndDistinguishExpression (C:\xampp\htdocs\ONLINE\CF7\cf7vi       sualPlugin\wp-content\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\d       ist\acorn.js:1861:32) 
    at Parser.pp$3.parseExprAtom (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content       \plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1796:19) 
@ ./lite.js 2:0-24 

回答

0

尝试改变这一行:

包括:__dirname + '/ src' 中,

这样:

排除:/ node_modules /,

+0

有一个排除了。你的意思是包括:path.join('_ dirname','/ src') –

+0

啊,你说得对。我建议删除包含,只留下排除。 –

1

它通过改变我的工作

include: __dirname + '/src', 

include: path.join(__dirname, 'src') 
相关问题