- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 yeoman 搭建了一个 Angular webapp。我成功创建了运行良好的网络应用程序!
我现在正在尝试将其投入生产。我注册了一个任务构建,但不幸的是,我没有设法找到适当的资源来详细解释这是如何完成的。
到目前为止,我在运行 grunt build
后设法拥有一个带有包含和缩小的 css 和 html 文件的 webapp,但我无法包含脚本。
问题:index.html文件中build block的作用是什么? yeoman 生成器的 index.html 文件带有一些 vendor.js 等。我保留那些吗?
如果有人能总结出成功构建您的 yeoman 应用程序必须采取的步骤,我将不胜感激。
无论如何我都会发布我的 Gruntfile 和 index.html,这是我的 Gruntfile:
'use strict';
module.exports = function (grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);
// Configurable paths for the application
var appConfig = {
app: require('./bower.json').appPath || 'app',
dist: 'dist'
};
// Define the configuration for all the tasks
grunt.initConfig({
// Project settings
yeoman: appConfig,
// Watches files for changes and runs tasks based on the changed files
watch: {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
},
js: {
files: ['<%= yeoman.app %>/**/*.js'],
tasks: ['newer:jshint:all'],
options: {
livereload: '<%= connect.options.livereload %>'
}
},
jsTest: {
files: ['test/spec/{,*/}*.js'],
tasks: ['newer:jshint:test', 'karma']
},
compass: {
files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],
tasks: ['compass:server', 'autoprefixer']
},
gruntfile: {
files: ['Gruntfile.js']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'<%= yeoman.app %>/**/*.html',
'.tmp/styles/{,*/}*.css',
'<%= yeoman.app %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
]
}
},
// The actual grunt server settings
connect: {
options: {
port: 9000,
// Change this to '0.0.0.0' to access the server from outside.
hostname: 'localhost',
livereload: 35729
},
proxies: [{
context: '/gemsbok-web/rest/api', // the context of the data service
host: 'localhost', // wherever the data service is running
port: 8080, // the port that the data service is running on
}],
livereload: {
options: {
open: true,
middleware: function (connect) {
// Setup the proxy
var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];
middlewares.push(connect.static('.tmp'));
middlewares.push(connect().use(
'/bower_components',
connect.static('./bower_components')
));
middlewares.push(connect.static(appConfig.app));
return middlewares;
}
}
},
test: {
options: {
port: 9001,
middleware: function (connect) {
return [
connect.static('.tmp'),
connect.static('test'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app)
];
}
}
},
dist: {
options: {
open: true,
base: '<%= yeoman.dist %>'
}
}
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: {
src: [
'Gruntfile.js',
'<%= yeoman.app %>/scripts/{,*/}*.js'
]
},
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/spec/{,*/}*.js']
}
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'<%= yeoman.dist %>',
'!<%= yeoman.dist %>/.git*'
]
}]
},
server: '.tmp'
},
// Add vendor prefixed styles
autoprefixer: {
options: {
browsers: ['last 1 version']
},
dist: {
files: [{
expand: true,
cwd: '.tmp/styles/',
src: '{,*/}*.css',
dest: '.tmp/styles/'
}]
}
},
// Automatically inject Bower components into the app
wiredep: {
options: {
// cwd: '<%= yeoman.app %>'
},
app: {
src: ['<%= yeoman.app %>/index.html'],
ignorePath: /\.\.\//
},
sass: {
src: ['<%= yeoman.app %>/common/styles/{,*/}*.{scss,sass}'],
ignorePath: /(\.\.\/){1,2}bower_components\//
}
},
// Compiles Sass to CSS and generates necessary files if requested
compass: {
options: {
sassDir: '<%= yeoman.app %>/styles',
cssDir: '.tmp/styles',
generatedImagesDir: '.tmp/images/generated',
imagesDir: '<%= yeoman.app %>/common/images',
javascriptsDir: '<%= yeoman.app %>/common', //guessed
fontsDir: '<%= yeoman.app %>/styles/fonts',
importPath: './bower_components',
httpImagesPath: '/images',
httpGeneratedImagesPath: '/images/generated',
httpFontsPath: '/styles/fonts',
httpPath: '../',
relativeAssets: false,
assetCacheBuster: false,
raw: 'Sass::Script::Number.precision = 10\n' //,
},
dist: {
options: {
generatedImagesDir: '<%= yeoman.dist %>/images/generated'
}
},
server: {
options: {
debugInfo: true
}
}
},
// Renames files for browser caching purposes
filerev: {
dist: {
src: [
'<%= yeoman.dist %>/scripts/{,*/}*.js',
'<%= yeoman.dist %>/styles/{,*/}*.css',
'<%= yeoman.dist %>/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
'<%= yeoman.dist %>/styles/fonts/*'
]
}
},
// Reads HTML for usemin blocks to enable smart builds that automatically
// concat, minify and revision files. Creates configurations in memory so
// additional tasks can operate on them
useminPrepare: {
html: '<%= yeoman.app %>/index.html',
options: {
dest: '<%= yeoman.dist %>'
}
},
// Performs rewrites based on filerev and the useminPrepare configuration
usemin: {
html: ['<%= yeoman.dist %>/{,*/}*.html'],
css: ['<%= yeoman.dist %>/common/styles/{,*/}*.css'],
options: {
assetsDirs: ['<%= yeoman.dist %>','<%= yeoman.dist %>/images']
}
},
// The following *-min tasks will produce minified files in the dist folder
// By default, your `index.html`'s <!-- Usemin block --> will take care of
// minification. These next options are pre-configured if you do not wish
// to use the Usemin blocks.
// cssmin: {
// dist: {
// files: {
// '<%= yeoman.dist %>/styles/main.css': [
// '.tmp/styles/{,*/}*.css'
// ]
// }
// }
// },
// uglify: {
// dist: {
// files: {
// '<%= yeoman.dist %>/scripts/scripts.js': [
// '<%= yeoman.dist %>/scripts/scripts.js'
// ]
// }
// }
// },
// concat: {
// dist: {}
// },
imagemin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.{png,jpg,jpeg,gif}',
dest: '<%= yeoman.dist %>/images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: '<%= yeoman.app %>/images',
src: '{,*/}*.svg',
dest: '<%= yeoman.dist %>/images'
}]
}
},
htmlmin: {
dist: {
options: {
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeCommentsFromCDATA: true,
removeOptionalTags: true
},
files: [{
expand: true,
cwd: '<%= yeoman.dist %>',
src: ['*.html', 'views/{,*/}*.html'],
dest: '<%= yeoman.dist %>'
}]
}
},
// ngmin tries to make the code safe for minification automatically by
// using the Angular long form for dependency injection. It doesn't work on
// things like resolve or inject so those have to be done manually.
ngmin: {
dist: {
files: [{
expand: true,
cwd: '.tmp/concat/scripts',
src: '*.js',
dest: '.tmp/concat/scripts'
}]
}
},
// Replace Google CDN references
cdnify: {
dist: {
html: ['<%= yeoman.dist %>/*.html']
}
},
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= yeoman.app %>',
dest: '<%= yeoman.dist %>',
src: [
'*.{ico,png,txt}',
'.htaccess',
'*.html',
'views/{,*/}*.html',
'images/{,*/}*.{webp}',
'fonts/*',
'bower_components/**/*'
]
}, {
expand: true,
cwd: '.tmp/images',
dest: '<%= yeoman.dist %>/images',
src: ['generated/*']
}]
},
styles: {
expand: true,
cwd: '<%= yeoman.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
// Run some tasks in parallel to speed up the build process
concurrent: {
server: [
'compass:server'
],
test: [
'compass'
],
dist: [
'compass:dist',
'imagemin',
'svgmin'
]
},
// Test settings
karma: {
unit: {
configFile: 'test/karma.conf.js',
singleRun: true
}
}
});
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',
'concurrent:server',
'autoprefixer',
'configureProxies:server',
'connect:livereload',
'watch'
]);
});
grunt.registerTask('server', 'DEPRECATED TASK. Use the "serve" task instead', function (target) {
grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.');
grunt.task.run(['serve:' + target]);
});
grunt.registerTask('test', [
'clean:server',
'concurrent:test',
'autoprefixer',
'connect:test',
'karma'
]);
grunt.registerTask('build', [
'clean:dist',
'wiredep',
'useminPrepare',
'concurrent:dist',
'autoprefixer',
'concat',
'ngmin',
'copy:dist',
'cdnify',
'cssmin',
'uglify',
'filerev',
'usemin',
'htmlmin'
]);
grunt.registerTask('default', [
'newer:jshint',
'test',
'build'
]);
};
这是我在应用程序中的 index.html:
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
<!-- build:css(.) styles/vendor.css -->
<!-- bower:css -->
<link rel="stylesheet" href="../bower_components/font-awesome/css/font-awesome.css" />
<link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="../bower_components/nvd3/src/nv.d3.css" />
<!-- endbower -->
<!-- endbuild -->
<!-- build:css(.tmp) styles/main.css -->
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
</head>
<body ng-app="antelopeApp" ng-controller="navigationCtrl">
<!--[if lt IE 7]>
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
<![endif]-->
<!-- Add your site or application content here -->
<div class="container">
<div class="header">
<ul class="nav nav-pills pull-right">
<li class="active"><a ng-href="#">Home</a></li>
<li><a ng-href="#/about">About</a></li>
<li><a ng-href="#">Contact</a></li>
</ul>
<h3 class="text-muted">antelope</h3>
</div>
<div ng-view="" >
</div>
<div class="footer">
<p><span class="glyphicon glyphicon-copyright-mark"></span> Codean Ltd 2008 - 2014. All Rights Reserved.</p>
</div>
</div>
<!-- build:js(.) scripts/oldieshim.js -->
<!--[if lt IE 9]>
<script src="../bower_components/es5-shim/es5-shim.js"></script>
<script src="../bower_components/json3/lib/json3.min.js"></script>
<![endif]-->
<!-- endbuild -->
<!-- build:js(.) scripts/vendor.js -->
<!-- bower:js -->
<script src="../bower_components/jquery/jquery.js"></script>
<script src="../bower_components/angular/angular.js"></script>
<script src="../bower_components/json3/lib/json3.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/affix.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/alert.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/button.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/carousel.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/collapse.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/dropdown.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tab.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/transition.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/scrollspy.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/modal.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/tooltip.js"></script>
<script src="../bower_components/bootstrap-sass-official/assets/javascripts/bootstrap/popover.js"></script>
<script src="../bower_components/jquery-ui/ui/jquery-ui.js"></script>
<script src="../bower_components/bootstrap/dist/js/bootstrap.js"></script>
<script src="../bower_components/angular-dashboard-framework/dist/angular-dashboard-framework.min.js"></script>
<script src="../bower_components/d3/d3.js"></script>
<script src="../bower_components/nvd3/nv.d3.js"></script>
<script src="../bower_components/angular-nvd3/dist/angular-nvd3.min.js"></script>
<script src="../bower_components/angular-local-storage/angular-local-storage.js"></script>
<script src="../bower_components/angular-resource/angular-resource.js"></script>
<script src="../bower_components/angular-cookies/angular-cookies.js"></script>
<script src="../bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="../bower_components/angular-animate/angular-animate.js"></script>
<script src="../bower_components/angular-touch/angular-touch.js"></script>
<script src="../bower_components/angular-route/angular-route.js"></script>
<!-- endbower -->
<!-- endbuild -->
<!-- build:js js/sample.min.js -->
<!-- angular-bootstrap -->
<script src="../bower_components/angular-bootstrap/ui-bootstrap.js"></script>
<script src="../bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script>
<!-- endbuild -->
<!-- build:js({.tmp,app}) scripts/scripts.js -->
<script src="app.js"></script>
<script src="pages/main/main.js"></script>
<script src="pages/about/about.js"></script>
<script src="directives/bluebox.js"></script>
<script src="pages/dashboard/provider.js"></script>
<script src="pages/dashboard/sortable.js"></script>
<script src="pages/dashboard/widget-content.js"></script>
<script src="pages/dashboard/widget.js"></script>
<script src="pages/dashboard/dashboard.js"></script>
<script src="pages/dashboard/sample.js"></script>
<script src="pages/dashboard/sampleModel.js"></script>
<script src="pages/dashboard/structures.js"></script>
<!-- endbuild -->
<script src="pages/dashboard/nvd3chart.js"></script>
最佳答案
我一直在使用 MEANjs,我的做法如下:
1) 在您的 Dev_Server/myAppFolder 下执行 ->
* npm install grunt-cli && npm install grunt
* export NODE_ENV=development && npm install // this will depend on prod or dev builds assuming you have multiple configuration ports i.e. 3000/dev, 8000/prod
* grunt build
现在你有了/dist 文件夹,你可以用它来运行你的应用
2) 将其复制到您的 Prod_Server/myAppFolder
您可以使用 githook、post-receive、rsync 等来完成此操作。在那里你可以做
* npm install grunt-cli && npm install grunt //you can do with -g for grunt only if needed
* export NODE_ENV=production && npm install --production // notice the production option
* node myServerFile.js
最后,您可以创建一个 UPSTART 脚本//假设您在 linux 环境中,这样它将启动您的应用程序作为服务。你可以用这个做很多事情/conf,但关于你的问题,我认为这可以给你提示做什么
关于javascript - 如何成功 'grunt build' 一个 yeoman 项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25769647/
我正在尝试全新安装 Yeoman,但在我尝试使用以下命令将其删除后,Yo 命令仍然存在: sudo npm remove -g yeoman npm remove -g yeoman sudo npm
当 yeoman 以嵌入形式运行时,我无法运行子生成器。 integrating yeoman in other tools 的文档提供这个例子: var yeoman = require('yeom
使用最新的 yeoman 更新 1.0,我们是否能够更改创建目录结构的方式?例如...如果我想在根目录而不是“/app”文件夹中创建我的文件,这可能吗?另外,如果我们想将我们的 Assets 文件夹命
我喜欢 Yeoman 的功能,例如 Package Manager (Bower)、Livereload 集成、Compass 等。 因此,我想用它来处理我的公共(public)网站。但是,我不想使用
我是创建 Yeoman Generator 的新手。我使用了 generator-generator 来让我开始,我经历了创建它、测试和把它全部搞定的过程。 在创建 yo 生成器的 tuts 中,他们
为什么不推荐 Yeoman 在他们的网站上写网站时建立网站 http://yeoman.io/road.html Clearing up misconceptions […] - Not recomm
尝试执行yo angular时出现以下错误: 在脚手架中,还有其他错误消息。 我做了: npm install -g yonpm install -g generator-angularyo angu
我试过console.log('message') ,但它以黑色返回消息。 有没有办法在生成器中记录彩色消息? 最佳答案 对于查看此问题的新用户 console.log();根据 Documentat
我正在为一个相当典型的节点应用程序构建一个自耕农生成器: / |--package.json |--.gitignore |--.travis.yml |--README.md |--app/
几个月前,我使用生成器角度来搭建一个项目,整个生态系统(karma、Node 版本、grunt 包)已经取得了相当大的进展。我在运行测试、构建东西等方面不断遇到问题。 我知道我可以使用 nvm 降级我
我不小心安装了一个我不想要的生成器。 我找不到任何方法来删除它。 我应该怎么做才能实现这个目标? 最佳答案 生成器只是普通的 npm 模块,因此您可以使用以下命令删除它 npm uninstall -
我创建了一个 Yeoman 生成器并希望我的团队使用它。 如果我在 Github 上更新我的生成器会发生什么?他们在本地安装了旧版本的生成器。他们是否总是需要重新安装才能获得最新版本? 团队成员不知道
我正在构建一个生成器,最后我需要在应用程序的某个目录中进行npm install,我尝试了以下操作: this.spawnCommandSync('cd', [this.destinationRoot
在使用 Yeoman 搭建脚手架时,我想用模板替换应用程序中的部分内容。一切似乎都很顺利,但我在脚手架期间遇到了此冲突错误。 这个. 模板( '条件文件/html/_signup.email.html
我是一名 javascript 初学者,通过遵循编写第一个生成器教程并阅读其他生成器代码,我已经成功地使用我的第一个生成器实现了这一目标。 我尝试了各种方法来使其正常工作,但都失败了,如果有人能指出我
我正在为 yeoman 使用角度生成器,目前默认行为是我这样做的时候 yo angular:controller testController 我创建了 2 个文件 create app\script
所以我一直在为我的项目使用 yeoman.io,并且我为我的图像设置了文件夹结构。但是当我构建它时,我的文件的文件名发生了变化。 我什至使用: $ yeoman build:text 因为我只想缩小我
如何通过自耕农生成器创建一个空目录? 我看过 mem-fs-editor ,但据我所知,只有在创建子文件时才会创建目录。我试过在子目录中创建一个文件,然后删除该文件,但这不起作用(我假设因为 mem-
我正在构建一个生成器,其中部分包含来自使用 exec 创建的另一个项目的脚手架.根据用户输入,我需要移动或删除此脚手架的一部分。 现在我正在用节点的 fs.child_process.spawn 做这
我正在跟踪yeoman.io上列出的示例Yeoman工作流程: npm install -g generator-angular generator-karma # install generato
我是一名优秀的程序员,十分优秀!