2017-09-25 69 views
1

我捆綁使用咕嚕-的contrib-CONCAT不同勢JS庫如下:捆綁的JS庫例如角,jQuery的,EVAL後lodash拋出「要求沒有定義」

dist7: { 
    src: [ 
     'lib/jquery/dist/jquery.js', 
     'lib/ng1.6/angular-animate/angular-animate.js', 
     'lib/ng1.6/angular-aria/angular-aria.js', 
     'lib/ng1.6/angular-messages/angular-messages.js', 
     'lib/api-check/dist/api-check.js', 
     'lib/angular-formly/dist/formly.js', 
     'lib/ng1.6/angular-sanitize/angular-sanitize.js', 
     'lib/angular-ui-router/release/angular-ui-router.js', 
     'lib/lodash/lodash.js', 
     'lib/angularjs-toaster/toaster.js', 
     'lib/moment/min/moment-with-locales.js', 
     'lib/eventie/eventie.js', 
     'lib/wolfy87-eventemitter/EventEmitter.js', 
     'lib/imagesloaded/imagesloaded.js', 
     'lib/desandro-matches-selector/matches-selector.js', 
     'lib/doc-ready/doc-ready.js', 
     'lib/fizzy-ui-utils/utils.js', 
     'lib/desandro-get-style-property/get-style-property.js', 
     'lib/get-size/get-size.js', 
     'lib/outlayer/item.js', 
     'lib/outlayer/outlayer.js', 
     'lib/masonry-layout/masonry.js'], 
    dest: 'dist/js/my-dependencies.js' 
} 

當我添加腳本標籤dist/js/my-dependencies.js它的工作原理。

但是當我做了讀取請求,然後我做的eval像以下:

fetch('dist/js/my-dependencies.js', {method: 'GET'}) 
    .then(response => response.text()))).then(scr => { 
     eval(scr) 
    }); 

它thoows如下因素的錯誤:

Err in evaling: /cuicui/scripts/js/my-dependencies.js With err: 
ReferenceError: require is not defined 
    at installedModules (eval at <anonymous> (cd.component.js:12), <anonymous>:1:93) 
    at eval (eval at <anonymous> (cd.component.js:12), <anonymous>:1:554) 
    at cd.component.js:12 
    at Array.forEach (<anonymous>) 
    at cd.component.js:12 
    at <anonymous> 

回答

1

問題: 你的一個依賴關係的有require('someLib')在文件的頂部(概率)。

如何找到: 經過各libary並做關鍵字require

搜索爲什麼EVAL失敗? eval()不在節點中。因此,它不知道如何處理該關鍵字。我會建議找到所有庫的預先版本,而不是使用庫源。

+0

需求被一些類似內部使用的庫所使用,但我不確定它們從哪裏解決? –

相關問題