我有这个自生的GruntFile.js。当我运行“grunt”时,dist文件夹不会更改bower_components / *。js中的所有脚本,只会更改其中的一部分。
以下是dist文件夹
中的index.html示例<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular.min.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular-resource.min.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular-sanitize.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular-animate.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular-touch.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular-route.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.11/angular-messages.min.js"></script>
<script src="bower_components/angular-utf8-base64/angular-utf8-base64.js"></script>
<script src="bower_components/ng-table/ng-table.js"></script>
<script src="bower_components/lodash/dist/lodash.js"></script>
<script src="bower_components/angular-growl-v2/build/angular-growl.js"></script>
<script src="bower_components/nya-bootstrap-select/dist/js/nya-bs-select.js"></script>
正如您所看到的,它找不到要使用的正确js文件。我怎样才能解决这个问题? 我的css文件也是同样的问题
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css">
<link rel="stylesheet" href="bower_components/ng-table/ng-table.css">
<link rel="stylesheet" href="bower_components/angular-growl-v2/build/angular-growl.css">
<link rel="stylesheet" href="bower_components/nya-bootstrap-select/dist/css/nya-bs-select.css">
谢谢! 如果您发现我的GruntFile.js中的任何其他错误或改进,请告诉我
修改
这是我的bower.json文件
{
"name": "civilization-web",
"version": "0.0.0",
"dependencies": {
"angular": "~1.3.7",
"json3": "~3.3.1",
"es5-shim": "~3.1.0",
"bootstrap": "~3.3.1",
"angular-resource": "~1.3.7",
"angular-sanitize": "~1.3.7",
"angular-animate": "~1.3.7",
"angular-touch": "~1.3.7",
"angular-route": "~1.3.7",
"angular-utf8-base64": "~0.0.5",
"angular-messages": "~1.3.8",
"ng-table": "~0.3.3",
"angular-bootstrap": "~0.12.0",
"ng-file-upload": "~2.0.5",
"ng-file-upload-shim": "~2.0.5",
"lodash": "2.4.1",
"angular-growl-v2": "~0.7.3",
"nya-bootstrap-select": "~2.0.8"
},
"devDependencies": {
"angular-mocks": "~1.3.7",
"angular-scenario": "~1.3.7"
},
"appPath": "app",
"resolutions": {
"angular": "1.3.8"
}
}
这是我的package.json
{
"name": "civilizationweb",
"version": "0.0.0",
"dependencies": {},
"devDependencies": {
"grunt": "^0.4.5",
"grunt-autoprefixer": "^0.7.3",
"grunt-concurrent": "^0.5.0",
"grunt-contrib-clean": "^0.5.0",
"grunt-contrib-concat": "^0.4.0",
"grunt-contrib-connect": "^0.7.1",
"grunt-contrib-copy": "^0.5.0",
"grunt-contrib-cssmin": "^0.9.0",
"grunt-contrib-htmlmin": "^0.3.0",
"grunt-contrib-imagemin": "^0.8.1",
"grunt-contrib-jshint": "^0.10.0",
"grunt-contrib-uglify": "^0.4.0",
"grunt-contrib-watch": "^0.6.1",
"grunt-filerev": "^0.2.1",
"grunt-google-cdn": "^0.4.0",
"grunt-karma": "^0.9.0",
"grunt-newer": "^0.7.0",
"grunt-ng-annotate": "^0.10.0",
"grunt-svgmin": "^0.4.0",
"grunt-usemin": "^2.1.1",
"grunt-wiredep": "^1.7.0",
"jshint-stylish": "^0.2.0",
"karma": "^0.12.24",
"karma-jasmine": "^0.1.5",
"karma-phantomjs-launcher": "^0.1.4",
"load-grunt-tasks": "^0.4.0",
"time-grunt": "^0.3.1"
},
"engines": {
"node": ">=0.10.0"
},
"scripts": {
"test": "grunt test"
}
}
答案 0 :(得分:2)
除非你告诉grunt将这些文件复制到/ dist文件夹作为构建过程的一部分,否则它不会做任何事情。您可以使用grunt copy来执行此操作。
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.client %>',
dest: '<%= yeoman.dist %>/public',
src: [
'*.{ico,png,txt}',
'.htaccess',
'bower_components/**/*',
'assets/images/{,*/}*.{webp}',
'assets/fonts/**/*',
'index.html'
]
}, {
expand: true,
cwd: '.tmp/images',
dest: '<%= yeoman.dist %>/public/assets/images',
src: ['generated/*']
}, {
expand: true,
dest: '<%= yeoman.dist %>',
src: [
'package.json',
'server/**/*'
]
}]
},
styles: {
expand: true,
cwd: '<%= yeoman.client %>',
dest: '.tmp/',
src: ['{app,components}/**/*.css']
}
},
我建议你也使用concat / usemin来连接所有的javascript。
<!-- build:js({.tmp,client}) app/concat.js -->
<script src="app/app1.js"></script>
<script src="app/app2.js"></script>
<script src="app/app3.js"></script>
<!-- endbuild -->
这将使用<!-- build:js -->
标记之间的脚本标记创建一个concat.js文件。然后可以使用grunt copy复制此文件。
答案 1 :(得分:2)
我认为你需要在index.html中添加注释来告诉grunt应该添加CSS和JS文件的位置。此外,如果您手动更改这些标签之间的内容,它将在下次重启grunt时被覆盖(我注意到它不确定它是标准功能)
<!-- build:<type>(alternate search path) <path> -->
... HTML Markup, list of script / link tags.
<!-- endbuild -->
以下是角度生成器生成的内容:
<!-- build:js({client,node_modules}) app/vendor.js -->
<!-- bower:js -->
<!-- endbower --><% if(filters.socketio) { %>
<script src="socket.io-client/socket.io.js"></script><% } %>
<!-- endbuild -->
<!-- build:js({.tmp,client}) app/app.js -->
<script src="app/app.js"></script>
<!-- injector:js -->
<!-- endinjector -->
<!-- endbuild -->
您需要使用build语言封装grunt(以及bower for bower)
答案 2 :(得分:2)
Gruntfile.js中的usemin任务将查找
<!-- build:{{type}} {{path/fileName}} -->
和
<!-- endbuild -->
并将这两者之间列出的所有文件连接成一个文件并缩小。这个单一的缩小文件将写在您{{path / fileName}}
中提到的路径上...所以,如果我对它的理解很好,那么你的Grunt文件就完全可以了,你可能在index.html中缺少usemin注释块
将所有链接和脚本标记放在usemin块之间
例如,对于您的凉亭组件,您可以使用类似这样的东西
<!-- build:css(.) styles/vendor.css -->
<!-- bower:css -->
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="bower_components/ng-table/ng-table.css">
<link rel="stylesheet" href="bower_components/angular-growl-v2/build/angular-growl.css">
<link rel="stylesheet" href="bower_components/nya-bootstrap-select/dist/css/nya-bs-select.css">
<!-- endbower -->
<!-- endbuild -->
<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-aria/angular-aria.js"></script>
<script src="bower_components/angular-cookies/angular-cookies.js"></script>
<script src="bower_components/angular-messages/angular-messages.js"></script>
<script src="bower_components/angular-resource/angular-resource.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-touch/angular-touch.js"></script>
<!-- endbower -->
<!-- endbuild -->
注意:所有的bower组件css文件都将放在样式目录中的vendor.css中,即dist / styles / vendor.css和类似的bower组件js文件将进入scripts目录中的vendor.js即dist / scripts / vendor.js
...对于你自己的js和css文件,你可以使用类似的东西
<!-- build:css(.tmp) styles/main.css -->
<link rel="stylesheet" href="styles/css1.css">
<link rel="stylesheet" href="styles/css2.css">
<!-- endbuild -->
<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="scripts/app.js"></script>
<script src="scripts/controllers/main.js"></script>
<script src="scripts/controllers/about.js"></script>
<!-- endbuild -->
注意:这里所有的css文件都将放在样式目录中的main.css中,即dist / styles / main.css和类似的js文件将进入脚本目录中的main.js,即dist /脚本/ main.js
...希望它有所帮助:)
答案 3 :(得分:0)
检查您是否已在html文件中设置。这就是触发grunt uglyfy / css min任务的原因。 或者您可以在您的grunt配置文件中取消注释这些任务,并确保它们在构建任务中的联接中未被注释。 祝你好运