我是grunt的新手,并创建了一个我想要构建的angularjs项目。 我的useminPrepare:js显示如下输出: 寻找构建脚本HTML注释块
现在配置:
的concat: {}
丑化: {}
cssmin: {options:{root:../'}}
autoprefixer: {}
运行“useminPrepare:js”(useminPrepare)任务
所以似乎没有任何意见。
您能否给我一个提示,我如何配置输入。
我的项目布局是:
虽然我必须使用angularjs客户端,一个用于web的bootstrap,另一个用于mobile for mobile,我想分享所有服务和控制器的一部分。 web和mobile包含一个Gruntfile,并且应该是两个客户端项目。 这是构建我的用例的可接受方式吗?
客户项目的结构如下: indexmobile.html indexweb.html
而公共项目包含所有共享的东西(服务......)
我的 Gruntfile 是例如:
'use strict';
var fs = require('fs');
var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;
var parseString = require('xml2js').parseString;
var parseVersionFromPomXml = function () {
var version;
var pomXml = fs.readFileSync('../../../../pom.xml', "utf8");
parseString(pomXml, function (err, result) {
version = result.project.version[0];
});
return version;
};
var useminAutoprefixer = {
name: 'autoprefixer',
createConfig: require('grunt-usemin/lib/config/cssmin').createConfig
};
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
grunt.initConfig({
yeoman: {
// configurable paths
app: require('./bower.json').appPath || 'app',
dist: 'build/dist'
},
watch: {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
},
ngconstant: {
files: ['Gruntfile.js', 'pom.xml'],
tasks: ['ngconstant:dev']
},
styles: {
files: ['assets/styles/**/*.css']
},
livereload: {
options: {
livereload: 35729
},
files: [
'**/*.html',
'**/*.json',
'{.tmp/,}assets/styles/**/*.css',
'{.tmp/,}scripts/**/*.js',
'assets/images/**/*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
wiredep: {
app: {
src: ['../indexweb.html'],
exclude: [/angular-i18n/, /swagger-ui/]
},
test: {
src: '../../../test/javascript/web/karma.conf.js',
exclude: [/angular-i18n/, /swagger-ui/, /angular-scenario/],
ignorePath: /\.\.\/\.\.\//, // remove ../../ from paths of injected javascripts
devDependencies: true,
fileTypes: {
js: {
block: /(([\s\t]*)\/\/\s*bower:*(\S*))(\n|\r|.)*?(\/\/\s*endbower)/gi,
detect: {
js: /'(.*\.js)'/gi
},
replace: {
js: '\'{{filePath}}\','
}
}
}
}
},
connect: {
proxies: [
{
context: '/api',
host: 'localhost',
port: 8080,
https: false,
changeOrigin: false
},
{
context: '/metrics',
host: 'localhost',
port: 8080,
https: false,
changeOrigin: false
},
{
context: '/dump',
host: 'localhost',
port: 8080,
https: false,
changeOrigin: false
},
{
context: '/health',
host: 'localhost',
port: 8080,
https: false,
changeOrigin: false
},
{
context: '/configprops',
host: 'localhost',
port: 8080,
https: false,
changeOrigin: false
},
{
context: '/beans',
host: 'localhost',
port: 8080,
https: false,
changeOrigin: false
},
{
context: '/api-docs',
host: 'localhost',
port: 8080,
https: false,
changeOrigin: false
},
{
context: '/console',
host: 'localhost',
port: 8080,
https: false,
changeOrigin: false
}
],
options: {
port: 9000,
hostname: '0.0.0.0',
livereload: 35729
},
livereload: {
options: {
open: true,
base: [
'.tmp',
'.'
],
middleware: function (connect) {
return [
proxySnippet,
connect.static('.tmp'),
connect.static('.')
];
}
}
},
test: {
options: {
port: 9001,
base: [
'.tmp',
'test',
'.'
]
}
}
},
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>/*',
'!<%= yeoman.dist %>/.git*'
]
}]
},
server: '.tmp'
},
jshint: {
options: {
jshintrc: '.jshintrc'
},
all: [
'Gruntfile.js',
'app.js',
'../common/**/*.js',
'components/**/*.js'
]
},
concat: {
},
rev: {
dist: {
files: {
src: [
'<%= yeoman.dist %>/scripts/**/*.js',
'<%= yeoman.dist %>/assets/styles/**/*.css',
'<%= yeoman.dist %>/assets/images/**/*.{png,jpg,jpeg,gif,webp,svg}',
'<%= yeoman.dist %>/assets/fonts/*'
]
}
}
},
useminPrepare: {
html: ['bower_components/**/*.html', 'components/**/*.html', 'swagger-ui/**/*.html'],
js: ['components/**/*.js', '../common/components/**/*.js'],
options: {
dest: '<%= yeoman.dist %>',
flow: {
html: {
steps: {
js: ['concat', 'uglifyjs'],
css: ['cssmin', useminAutoprefixer] // Let cssmin concat files so it corrects relative paths to fonts and images
},
post: {}
}
}
}
},
usemin: {
html: ['<%= yeoman.dist %>/**/*.html'],
css: ['<%= yeoman.dist %>/assets/styles/**/*.css'],
js: ['<%= yeoman.dist %>/components/**/*.js'],
options: {
assetsDirs: ['<%= yeoman.dist %>', '<%= yeoman.dist %>/assets/styles', '<%= yeoman.dist %>/assets/images', '<%= yeoman.dist %>/assets/fonts'],
patterns: {
js: [
[/(assets\/images\/.*?\.(?:gif|jpeg|jpg|png|webp|svg))/gm, 'Update the JS to reference our revved images']
]
},
dirs: ['<%= yeoman.dist %>']
}
},
imagemin: {
dist: {
files: [{
expand: true,
cwd: 'assets/images',
src: '**/*.{jpg,jpeg}',
dest: '<%= yeoman.dist %>/assets/images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: 'assets/images',
src: '**/*.svg',
dest: '<%= yeoman.dist %>/assets/images'
}]
}
},
cssmin: {
options: {
root: '../'
}
},
ngtemplates: {
dist: {
cwd: '.',
src: ['components/**/*.html', '../common/components/**/*.html'],
dest: '.tmp/templates/templates.js',
options: {
module: 'rupcomApp',
usemin: 'app.js',
htmlmin: {
removeCommentsFromCDATA: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
conservativeCollapse: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true
}
}
}
},
htmlmin: {
dist: {
options: {
removeCommentsFromCDATA: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
conservativeCollapse: true,
removeAttributeQuotes: true,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
keepClosingSlash: true
},
files: [{
expand: true,
cwd: '<%= yeoman.dist %>',
src: ['*.html'],
dest: '<%= yeoman.dist %>'
}]
}
},
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '.',
dest: '<%= yeoman.dist %>',
src: [
'../indexweb.html',
'components/**/*.html',
'assets/images/**/*.{png,gif,webp}',
'assets/fonts/*'
],
rename: function (dest, src) {
return dest + "/" + src.replace('indexweb.html', 'dist/index.html');
}
}, {
expand: true,
cwd: '.tmp/assets/images',
dest: '<%= yeoman.dist %>/assets/images',
src: [
'generated/*'
]
}]
}
},
concurrent: {
server: [],
test: [],
dist: [
'imagemin',
'svgmin'
]
},
karma: {
unit: {
configFile: '../../../test/javascript/karma.conf.js',
singleRun: true
}
},
cdnify: {
dist: {
html: ['<%= yeoman.dist %>/*.html']
}
},
ngAnnotate: {
dist: {
files: [{
expand: true,
cwd: '.tmp/concat/scripts',
src: '*.js',
dest: '.tmp/concat/scripts'
}]
}
},
ngconstant: {
options: {
name: 'rupcomApp',
deps: false,
wrap: '"use strict";\n
},
dev: {
options: {
dest: 'app.constants.js'
},
constants: {
ENV: 'dev',
VERSION: parseVersionFromPomXml()
}
},
prod: {
options: {
dest: '.tmp/scripts/app/app.constants.js'
},
constants: {
ENV: 'prod',
VERSION: parseVersionFromPomXml()
}
}
}
});
grunt.registerTask('serve', [
'clean:server',
'wiredep',
'ngconstant:dev',
'concurrent:server',
'configureProxies',
'connect:livereload',
'watch'
]);
grunt.registerTask('server', function (target) {
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
grunt.task.run([target ? ('serve:' + target) : 'serve']);
});
grunt.registerTask('test', [
'clean:server',
'wiredep:test',
'ngconstant:dev',
'concurrent:test',
'connect:test',
'karma'
]);
grunt.registerTask('build', [
'clean:dist',
'wiredep:app',
'ngconstant:prod',
'useminPrepare',
'ngtemplates',
'concurrent:dist',
'concat',
'copy:dist',
'ngAnnotate',
'cssmin',
'autoprefixer',
'uglify',
'rev',
'usemin',
'htmlmin'
]);
grunt.registerTask('default', [
'test',
'build'
]);
};
提前致谢``
干杯 马库斯