0

我有一个使用 Yeoman 和 Grunt 构建的 Angular 项目。每次如果我运行命令:

sudo grunt serve 

应用程序是否正常启动但在 index.html 中从 bower_components 目录中删除了一些链接库。

外汇:

<script src="bower_components/spin.js/spin.js"></script>

所以我必须每次都恢复 git 中 index.html 文件的更改,然后才能继续测试。

有什么可能我可以解决这个烦人的问题吗?

谢谢你的帮助。

编辑:

我试过以下:

安装:

npm install grunt-script-inject

GrunFile.js

 // Automatically inject Bower components into the app
    wiredep: {
      app: {
        src: ['<%= yeoman.app %>/index.html'],
        ignorePath: new RegExp('^<%= yeoman.app %>/|../')
      },
    scriptinject: {
      dev: {
         srcs: ['<%= yeoman.client %>/bower_components/path/to/src/plugin.js',
                '<%= yeoman.client %>/bower_components/path/to/src/plugin2.js'] ,//order is important if this sciprt will be concated and minified
         html: '<%= yeoman.client %>/index.html', //file that as the block comment to look for a place to insert the script tags
         without: '<%= yeoman.client %>/' //this script will be used to remove this block of string of script tag file location
        }
      }
    },

 grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
    if (target === 'dist') {
      return grunt.task.run(['build', 'connect:dist:keepalive']);
    }

    grunt.task.run([
      'clean:server',
      'wiredep',
      'scripinject',
      'concurrent:server',
      'autoprefixer',
      'connect:livereload',
      'watch'
    ]);
  });

但是现在,在 grunt serve 之后,我看到以下错误:

Running "serve" task
Warning: Task "scripinject" not found. Use --force to continue.

Aborted due to warnings.

怎么了?

4

2 回答 2

1

我在 bower install 命令中使用--s解决了

所以:

bower install --save  angular-translate

工作正常。

这是文档:

http://bower.io/docs/api/#install

于 2014-10-14T08:37:45.213 回答
1

我有一个类似的问题。在 index.html 我添加了以下代码:

<script src="bower_components/highcharts-release/highcharts.js"></script>
<script src="bower_components/highcharts-release/modules/heatmap.js"></script>

每次我运行grunt servegrunt build命令时,grunt 都会将其重写为:

<script src="bower_components/highcharts-release/highcharts.js"></script>
<script src="bower_components/highcharts-release/highcharts-more.js"></script>
<script src="bower_components/highcharts-release/modules/exporting.js"></script>

所以我查看了bower_components/highcharts-release/bower.json文件并看到:

{
  "name": "highcharts",
  "version": "v4.1.4",
  "main": [
    "highcharts.js",
    "highcharts-more.js",
    "modules/exporting.js"
  ]
}

我将其更改为:

{
  "name": "highcharts",
  "version": "v4.1.4",
  "main": [
    "highcharts.js",
      "modules/heatmap.js"
  ]
}

现在一切都很好。希望它会对某人有所帮助,即使这是一个很晚的答案。

于 2015-04-13T08:54:40.083 回答