加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – 使用grunt的“bower_concat”和“angular-i18n”的

发布时间:2020-12-17 17:14:20 所属栏目:安全 来源:网络整理
导读:如果没有使用grunt的“concat”和“bower_concat”,则以这种方式使用angular-i18n: html ng-app head ... script src="angular.js"/script script src="i18n/angular-locale_de-de.js"/script ... /head /html (根据这里:https://docs.angularjs.org/guide
如果没有使用grunt的“concat”和“bower_concat”,则以这种方式使用angular-i18n:

<html ng-app>
    <head>
        ...
       <script src="angular.js"></script>
       <script src="i18n/angular-locale_de-de.js"></script>
        ...
    </head>
 </html>

(根据这里:https://docs.angularjs.org/guide/i18n)

但是……当然:我正在使用concat和bower_concat.
我这样使用它们:

>首先我使用bower_concat并创建build / bower-concat.js
??注意:bower_concat读取生活在bower_components中的每个子目录的每个bower.json,它连接所有主文件.
??注2:“angular-18n”的bower.json有“忽略”:[“** /.*”,…
>然后我将所有js(我的控制器等)连接到build / inouse-concat.js
>最后,我将bower-concat.js与inhouse-concat.js连接成all-concat.js
>< script src =“build / all-concat.js”>< / script>

所以我虽然可以在第三步中包含相应的语言环境“angular-i18n / angular-locale_de-de.js”,如下所示:

// inhouse js with bower's js with angular's i18n into one file
  allJsConcat: {
    src: ['build/bower-concat.js','bower_components/angular-i18n/angular-locale_de-de.js','build/inhouse-concat.js',],dest: 'build/all-concat.js',}

但这不起作用.我越来越:
?未捕获的ReferenceError:未定义require

问题:你如何推荐使用带角度的locale js的grunt,concat和bower_concat?我究竟做错了什么?

解决方法

该死的,我讨厌回答我自己的问题,因为急于问…

无论如何,这工作:

Gruntfile.js

bower_concat: {
        all: {
            dest: 'build/bower-concat.js',cssDest: 'build/bower-concat.css',exclude: [
                'angular-i18n'
            ],bowerOptions: {
                relative: false
            }
        }
    },concat: {
        ...

        allJsConcat: {
            src: ['build/bower-concat.js',}
    }

诀窍是使用grunt-bower-concat的exclude参数.

还有一个mainFiles参数,我认为也可以做到这一点:

mainFiles

Some Bower components don’t list their main files or (more likely)
don’t have bower.json file at all. In this case bower-concat will try
to guess main file but sometimes it can’t or choose wrong one. You
could explicitly define main files for that components.

所以我认为使用它也会起作用:

mainFiles: {
     'angular-i18n': 'angular-locale_de-de.js',}

没有做“三档concat”(所以它更优雅)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读