2017-02-10 69 views
0

無法使用webpack解析動態要求。收到錯誤webpack中的動態要求不起作用

WARNING in ./ace/config.js 
112:21-40 Critical dependency: the request of a dependency is an expression 

WARNING in ./ace/config.js 
142:39-46 Critical dependency: require function is used in a way in which 
dependencies cannot be statically extracted   

WARNING in ./ace/config.js 
124:12-131:14 Critical dependency: the request of a dependency is an 
expression 

有5個文件使用靜態要求,只有1動態需要的文件。

我的WebPack配置文件是這樣的

var webpack = require('webpack'); 

module.exports = { 
context: __dirname + '/app', 
entry: { 
    services: ["./init.js"] 
}, 
output: { 
    path: __dirname + '/public/javascript', 
    filename: "[name].bundle.js?v=[hash]" 
}, 
module: { 
    loaders: [ 
     { test: /\.json$/, loader: 'json-loader' }, 
     { 
      loader: 'babel-loader', 
      query: { 
       presets: ['es2015', 'stage-0'] 
      } 
     }, 
     { test: /\.css$/, loader: "css-loader" } 
    ] 
}, 
node: { 
    console: true, 
    fs: 'empty', 
    net: 'empty', 
    tls: 'empty' 
}, 
target: 'node' 
}; 
+0

嘗試使用預編譯的版本從王牌建立, –

回答

1

我們需要解決這些動態使用的WebPack功能 [https://webpack.github.io/docs/context.html][1]

要求只需要提從那裏的WebPack可以解決這些目錄依賴關係。您也可以探索webpack的ContextReplacementPlugin。

this => require([module]) 
    to => require(['./directory/' + module + '.js']) 

,其中模塊名稱是動態