【发布时间】:2026-02-19 11:50:01
【问题描述】:
我有一个使用 Yeoman 和 Grunt 构建的 Angular 项目。每次如果我运行命令:
sudo grunt serve
应用程序是否正常启动,但 index.html 中的一些链接库已从 bower_components 目录中删除。
FXP:
<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.
怎么了?
【问题讨论】:
-
只是因为在 grunt.task.run 中没有提到 'scripinject' 应该是 'scriptinject'。因此“找不到任务“scripinject””。
标签: angularjs gruntjs yeoman yeoman-generator-angular