问题描述
这是我的 index.html
中的相关部分:
<! - build:js scripts / scripts.js - >
< script src =scripts / vendor / jquery.js>< / script>
< script src =scripts / vendor / bootstrap.min.js>< / script>
< script src =scripts / vendor / handlebars.runtime.js>< / script>
< script src =scripts / vendor / ember.js>< / script>
< script src =scripts / vendor / ember-data.js>< / script>
< script src =scripts / templates.js>< / script>
< script src =scripts / neuterapp.js>< / script>
<! - endbuild - >
(但最后两个信息是错误的,实际上是我的问题)
这是 Gruntfile.js
的相关部分:
useminPrepare:{
html:'<%= yeoman.app%> /index.html',
选项:{
dest:'<% = yeoman.dist%>'
}
},
usemin:{
html:['<%= yeoman.dist%> / *。html'] ,
css:['<%= yeoman.dist%> / styles / *。css'],
options:{
dirs:['<%= yeoman.dist %>']
}
},
是 templates.js
和 neuterapp.js
是生成的文件,所以它们不在<%= yeoman.app%> / scripts
,但在<%= yeoman.dist%> / scripts
/ p>
这是我的(简体)目录结构:
webapp /
├──app
│├──app.js< --- for neuter
│├──controllers
│├──index.html
│├──车型
│├──路线
│├──脚本
││└──卖家< --- for usemin
│├─ ─模板< --- for ember_templates
││├──template1.hbs
││└──template2.hbs
│└──views
├──dist
│├──index.html
│└──脚本
│├──neuterapp.js │└──templates.js └──Gruntfile.js
如何判断 usemin
包含一些生成的文件?
在需要的情况下,这些是 neuter
和 ember_templates
:
neuter:{
选项:{
includeSourceURL:true
},
'<%= yeoman.dist%> /scripts/neuterapp.js':'<%= yeoman.app%> ; /app.js'
},
ember_templates:{
compile:{
options:{
templateName:function(sourceFile){
return sourceFile .replace(/ app \ / templates \ //,''); //<%= yeoman.dist%> / scripts /
}
},
文件:{
'<%= yeoman.dist%> / scripts /templates.js':[
'<%= yeoman.app%> / templates / ** / *。hbs'
]
}
} $ b $您可能会使用,准备在临时位置使用usemin需求。
我建议你做的是:
- 将您需要的应用程序文件从应用程序复制到 temp
- 让生成文件的任务输出到 temp
- 让
usemin
& useminPrepare
任务在 temp 上运行并输出到 dist 。
This is the relevant part in my index.html
:
<!-- build:js scripts/scripts.js -->
<script src="scripts/vendor/jquery.js"></script>
<script src="scripts/vendor/bootstrap.min.js"></script>
<script src="scripts/vendor/handlebars.runtime.js"></script>
<script src="scripts/vendor/ember.js"></script>
<script src="scripts/vendor/ember-data.js"></script>
<script src="scripts/templates.js"></script>
<script src="scripts/neuterapp.js"></script>
<!-- endbuild -->
(but the last two entrires are wrong, that is actually my problem)
This is the relevant part of the Gruntfile.js
:
useminPrepare: {
html: '<%= yeoman.app %>/index.html',
options: {
dest: '<%= yeoman.dist %>'
}
},
usemin: {
html: ['<%= yeoman.dist %>/*.html'],
css: ['<%= yeoman.dist %>/styles/*.css'],
options: {
dirs: ['<%= yeoman.dist %>']
}
},
The problem that I have is that both templates.js
and neuterapp.js
are generated files, so they are not in <%= yeoman.app %>/scripts
, but in <%= yeoman.dist %>/scripts
.
This is my (simplified) directory structure:
webapp/
├── app
│ ├── app.js <--- for neuter
│ ├── controllers
│ ├── index.html
│ ├── models
│ ├── routes
│ ├── scripts
│ │ └── vendor <--- for usemin
│ ├── templates <--- for ember_templates
│ │ ├── template1.hbs
│ │ └── template2.hbs
│ └── views
├── dist
│ ├── index.html
│ └── scripts
│ ├── neuterapp.js <--- this must also be used for usemin!!!
│ └── templates.js <--- this must also be used for usemin!!!
└── Gruntfile.js
How can I tell usemin
to include some generated files?
And in case this is needed, these are the configurations of neuter
and ember_templates
:
neuter: {
options: {
includeSourceURL: true
},
'<%= yeoman.dist %>/scripts/neuterapp.js': '<%= yeoman.app %>/app.js'
},
ember_templates: {
compile: {
options: {
templateName: function (sourceFile) {
return sourceFile.replace(/app\/templates\//, ''); // <%= yeoman.dist %>/scripts/
}
},
files: {
'<%= yeoman.dist %>/scripts/templates.js': [
'<%= yeoman.app %>/templates/**/*.hbs'
]
}
}
},
解决方案 You might use the copy task to prepare what usemin needs in a temporary location.
What I suggest you do:
- copy your needed app files from app to temp
- Let your tasks which generate files output to temp
- let your
usemin
& useminPrepare
task run on temp and output to dist.
这篇关于Grunt:在usemin中包含一个生成的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!