【问题标题】:In Meanjs, adding new lib in bower.json not automatically added to the config file在 Meanjs 中,在 bower.json 中添加新库不会自动添加到配置文件中
【发布时间】:2014-10-19 11:41:56
【问题描述】:

我正在学习 Meanjs。我需要为我的项目添加 Fontawesome。所以我在 bower.json 中添加了一个条目如下:

"dependencies": {
    "bootstrap": "~3",
    "angular": "~1.2",
    "angular-resource": "~1.2",
    "angular-mocks": "~1.2",
    "angular-cookies": "~1.2",
    "angular-animate": "~1.2",
    "angular-touch": "~1.2",
    "angular-sanitize": "~1.2",
    "angular-bootstrap": "~0.11.0",
    "angular-ui-utils": "~0.1.1",
    "angular-ui-router": "~0.2.10",
    "fontawesome": "~4.1.0"
}

并运行“凉亭安装”。包下载成功,但 fontawesome 没有在我的页面中自动链接。我是否必须手动链接这些库?

请帮忙。

【问题讨论】:

  • 在 "AngularJS generator(github.com/yeoman/generator-angular)" 项目中,如果你在 bower.json 中为额外的库添加一个条目,它会自动将这些链接到索引页面,最终你可以在你所有的库中使用这些库页。这些库没有手动链接。我的问题是:'MEAN.js 中是否有任何自动机制可用于类似的功能'?

标签: javascript bower meanjs


【解决方案1】:

您缺少的步骤是在 config/env/*.js 文件中添加条目。有一个库部分,您将在其中看到其他库。 config/env 文件决定了添加到 head 标签的链接。

我不知道添加这些条目的自动方法。

【讨论】:

  • 为我工作,我添加了以下内容:css: [ 'public/modules/**/css/*.css', 'public/lib/fontawesome/css/font-awesome.min.css' ]
【解决方案2】:

发给:
"meanjs-version": "0.4.2"

将库的路径添加到:
/config/assets/*.js

示例:
/config/assets/default.js

module.exports = {
  client: {
    lib: {
      css: [
        'public/lib/bootstrap/dist/css/bootstrap.css',
        'public/lib/bootstrap/dist/css/bootstrap-theme.css',
        'public/lib/angular-typewrite/dist/angular-typewrite.css'
      ],
      js: [
        'public/lib/angular/angular.js',
        'public/lib/angular-resource/angular-resource.js',
        'public/lib/angular-typewrite/dist/angular-typewrite.js'
      ]
    }
   }
}
}

【讨论】:

    【解决方案3】:

    为了自动更新依赖关系,我过去使用过wiredep。

    npm install --save-dev grunt-wiredep
    

    在您的 Gruntfile.js 中,您将有一个如下所示的块:

    grunt.initConfig({
    
     //bunch of tasks in here
     clean: {...},
     jshint:{...},
     //add the following lines
      wiredep: {
        src: ['<%= yeoman.app %>/index.html', 'you can add', 'other search paths', 'here'],
        block: /(([ \t]*)\/\/\s*bower:*(\S*))(\n|\r|.)*?(\/\/\s*endbower)/gi,  
        replace: {
          js: '{{filePath}}',
         }
        }
      });
    

    添加为任务后,将该任务添加到您的任务列表中

    grunt.registerTask('testOrWhateverYoursIsCalled', [
      //your other tasks here
      'wiredep'
     ]);
    

    然后在你的 .config 文件或任何你有大量 js 文件的地方添加:

     //bower:js
     //this will get swapped out for your list of bower components
     //endbower
    

    路径可能很奇怪,但我认为您可以使用 cwd 来更改路径。不知道怎么做,只是玩了用wiredep替换东西,它起作用了!!

    刚刚回答了我在堆栈上的第一个问题,终于!!!

    【讨论】:

      【解决方案4】:

      可能你应该添加

      <link rel="stylesheet" href="bower_components/fontawesome/css/font-awesome.min.css">
      

      到你的 index.html

      【讨论】:

      • 在 meanjs 项目中,会自动添加指向 jsfile 的链接。问题是你必须做些什么来避免这个手动步骤。
      猜你喜欢
      • 2011-02-18
      • 2017-04-16
      • 1970-01-01
      • 2022-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 2015-04-26
      相关资源
      最近更新 更多