2017-09-25 65 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

需求被一些类似内部使用的库所使用,但我不确定它们从哪里解决? –

相关问题