本文将介绍css–yeomangrunt构建任务的详细情况,特别是关于css构造的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于angularjs–
本文将介绍css – yeoman grunt构建任务的详细情况,特别是关于css构造的相关信息。我们将通过案例分析、数据研究等多种方式,帮助您更全面地了解这个主题,同时也将涉及一些关于angularjs – Grunt Wiredep不会在Yeoman Angular Tutorial中注册bootstrap css文件、angularjs – Yeoman Angular app,grunt watch .less files、angularjs – 从新的Yeoman安装返回的grunt返回 – 警告:找不到任务“服务”、angularjs – 使用grunt构建角度应用程序,app无法加载的知识。
本文目录一览:- css – yeoman grunt构建任务(css构造)
- angularjs – Grunt Wiredep不会在Yeoman Angular Tutorial中注册bootstrap css文件
- angularjs – Yeoman Angular app,grunt watch .less files
- angularjs – 从新的Yeoman安装返回的grunt返回 – 警告:找不到任务“服务”
- angularjs – 使用grunt构建角度应用程序,app无法加载
css – yeoman grunt构建任务(css构造)
我在app / styles中创建了一个新的.scss文件test.scss,与main.scss分开.
在使用grunt构建时,我的所有.scss文件都已编译为css并在.tmp文件夹中创建,但只有main.css被移动到dist / style.我的test.css文件没有移动.
Gruntfile:
// Generated on 2014-04-01 using generator-webapp 0.4.7 'use strict'; // # Globbing // for performance reasons we're only matching one level down: // 'test/spec/{,*/}*.js' // use this if you want to recursively match all subfolders: // 'test/spec/**/*.js' 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); // Define the configuration for all the tasks grunt.initConfig({ // Project settings yeoman: { // Configurable paths app: 'app',dist: 'dist' },// Watches files for changes and runs tasks based on the changed files watch: { js: { files: ['<%= yeoman.app %>/scripts/{,*/}*.js'],tasks: ['jshint'],options: { livereload: true } },jstest: { files: ['test/spec/{,tasks: ['test:watch'] },gruntfile: { files: ['Gruntfile.js'] },compass: { files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'],tasks: ['compass:server','autoprefixer'] },styles: { files: ['<%= yeoman.app %>/styles/{,*/}*.css'],tasks: ['newer:copy:styles',livereload: { options: { livereload: '<%= connect.options.livereload %>' },files: [ '<%= yeoman.app %>/{,*/}*.html','.tmp/styles/{,*/}*.css','<%= yeoman.app %>/images/{,*/}*.{gif,jpeg,jpg,png,svg,webp}' ] } },// The actual grunt server settings connect: { options: { port: 9000,livereload: 35729,// Change this to '0.0.0.0' to access the server from outside hostname: 'localhost' },livereload: { options: { open: true,base: [ '.tmp','<%= yeoman.app %>' ] } },test: { options: { port: 9001,'test',dist: { options: { open: true,base: '<%= yeoman.dist %>',livereload: false } } },// Empties folders to start fresh clean: { dist: { files: [{ dot: true,src: [ '.tmp','<%= yeoman.dist %>/*','!<%= yeoman.dist %>/.git*' ] }] },server: '.tmp' },// Make sure code styles are up to par and there are no obvIoUs mistakes jshint: { options: { jshintrc: '.jshintrc',reporter: require('jshint-stylish') },all: [ 'Gruntfile.js','<%= yeoman.app %>/scripts/{,*/}*.js','!<%= yeoman.app %>/scripts/vendor/*','test/spec/{,*/}*.js' ] },// Mocha testing framework configuration options mocha: { all: { options: { run: true,urls: ['http://<%= connect.test.options.hostname %>:<%= connect.test.options.port %>/index.html'] } } },// 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 %>/images',javascriptsDir: '<%= yeoman.app %>/scripts',fontsDir: '<%= yeoman.app %>/styles/fonts',importPath: '<%= yeoman.app %>/bower_components',httpImagesPath: '/images',httpGeneratedImagesPath: '/images/generated',httpFontsPath: '/styles/fonts',relativeAssets: false,assetCacheBuster: false },dist: { options: { generatedImagesDir: '<%= yeoman.dist %>/images/generated' } },server: { options: { debugInfo: true } } },// Add vendor prefixed styles autoprefixer: { options: { browsers: ['last 2 version','ie 8','ie 9'] },dist: { files: [{ expand: true,cwd: '.tmp/styles/',src: '{,dest: '.tmp/styles/' }] } },// Automatically inject Bower components into the HTML file 'bower-install': { app: { html: '<%= yeoman.app %>/index.html',ignorePath: '<%= yeoman.app %>/' } },// Renames files for browser caching purposes rev: { dist: { files: { src: [ '<%= yeoman.dist %>/scripts/{,'<%= yeoman.dist %>/styles/{,'<%= yeoman.dist %>/images/{,webp}','<%= 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: { options: { dest: '<%= yeoman.dist %>' },html: '<%= yeoman.app %>/index.html' },// Performs rewrites based on rev and the useminPrepare configuration usemin: { options: { assetsDirs: ['<%= yeoman.dist %>'] },html: ['<%= yeoman.dist %>/{,*/}*.html'],css: ['<%= yeoman.dist %>/styles/{,*/}*.css'] },// The following *-min tasks produce minified files in the dist folder imagemin: { dist: { files: [{ expand: true,cwd: '<%= yeoman.app %>/images',png}',dest: '<%= yeoman.dist %>/images' }] } },svgmin: { dist: { files: [{ expand: true,*/}*.svg',htmlmin: { dist: { options: { collapseBooleanAttributes: true,collapseWhitespace: true,removeAttributeQuotes: true,removeCommentsFromCDATA: true,removeEmptyAttributes: true,removeOptionalTags: true,removeRedundantAttributes: true,useShortDoctype: true },files: [{ expand: true,cwd: '<%= yeoman.dist %>',dest: '<%= yeoman.dist %>' }] } },// 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/{,'<%= yeoman.app %>/styles/{,*/}*.css' ] } } },// uglify: { // dist: { // files: { // '<%= yeoman.dist %>/scripts/scripts.js': [ // '<%= yeoman.dist %>/scripts/scripts.js' // ] // } // } // },// concat: { // dist: {} // },// copies remaining files to places other tasks can use copy: { dist: { files: [{ expand: true,dot: true,cwd: '<%= yeoman.app %>',dest: '<%= yeoman.dist %>',src: [ '*.{ico,txt}','.htaccess','images/{,*/}*.webp','{,'styles/fonts/{,*/}*.*','bower_components/' + (this.includeCompass ? 'sass-' : '') + 'bootstrap/' + (this.includeCompass ? 'fonts/' : 'dist/fonts/') +'*.*' ] }] },styles: { expand: true,cwd: '<%= yeoman.app %>/styles',dest: '.tmp/styles/',*/}*.css' } },// Generates a custom Modernizr build that includes only the tests you // reference in your app modernizr: { devFile: '<%= yeoman.app %>/bower_components/modernizr/modernizr.js',outputFile: '<%= yeoman.dist %>/bower_components/modernizr/modernizr.js',files: [ '<%= yeoman.dist %>/scripts/{,'!<%= yeoman.dist %>/scripts/vendor/*' ],uglify: true },// Run some tasks in parallel to speed up build process concurrent: { server: [ 'compass:server','copy:styles' ],test: [ 'copy:styles' ],dist: [ 'compass','copy:styles','imagemin','svgmin' ] } }); grunt.registerTask('serve',function (target) { if (target === 'dist') { return grunt.task.run(['build','connect:dist:keepalive']); } grunt.task.run([ 'clean:server','concurrent:server','autoprefixer','connect:livereload','watch' ]); }); grunt.registerTask('server',function () { grunt.log.warn('The `server` task has been deprecated. Use `grunt serve` to start a server.'); grunt.task.run(['serve']); }); grunt.registerTask('test',function(target) { if (target !== 'watch') { grunt.task.run([ 'clean:server','concurrent:test',]); } grunt.task.run([ 'connect:test','mocha' ]); }); grunt.registerTask('build',[ 'clean:dist','compass:dist','useminPrepare','concurrent:dist','concat','cssmin','uglify','copy:dist','modernizr',//'rev','usemin' //'htmlmin' ]); grunt.registerTask('default',[ 'newer:jshint','build' ]); };
解决方法
如果您希望test.scss在那里,请查看index.html文件.
您将看到以下内容:
“`
<!-- build:css({.tmp,app}) styles/main.css --> <link rel="stylesheet" href="styles/main.css"> <link rel="stylesheet" href="styles/test.css"> <!-- endbuild -->
“`
在构建时,yeoman将查找所有这些文件并从中创建main.css.
angularjs – Grunt Wiredep不会在Yeoman Angular Tutorial中注册bootstrap css文件
Bootstrap JavaScript文件包含在index.html文件中.
这是正常的行为还是我想手动包含它?我希望运行Grunt Wiredep将引导程序css文件包含在<! - bower:css - ><! - endbower - >之间.占位符在index.html文件中?
"dependencies": { ... },"overrides": { "bootstrap": { "main": [ "dist/js/bootstrap.js","dist/css/bootstrap.css","less/bootstrap.less" ] } }
http://blog.getbootstrap.com/2015/06/15/bootstrap-3-3-5-released/
angularjs – Yeoman Angular app,grunt watch .less files
我当然已经安装了grunt-contrib-less模块
npm install grunt-contrib-less --save-dev
并将它保存到我的package.json.
我已经能够使用代码在其他项目中完成这项工作:
module.exports = function(grunt){ grunt.initConfig({ pkg:grunt.file.readJSON('package.json'),less:{ development:{ options: { paths: ['bower_components/bootstrap/less','bower_components/bootstrap/dist/css'],yuicompress: true },files:{ 'bower_components/bootstrap/dist/css/bootstrap.css' : 'bower_components/bootstrap/less/bootstrap.less',} } },// running 'grunt watch' will watch for changes watch: { files: ['bower_components/bootstrap/less/*.less','bower_components/bootstrap/less/*.less'],tasks: ['less'] } }); grunt.loadNpmtasks('grunt-contrib-less'); grunt.loadNpmtasks('grunt-contrib-watch'); grunt.registerTask('default',['less']); };
和:
module.exports = function(grunt) { grunt.initConfig({ less: { development: { options: { paths: ["bower_components/bootstrap/less"],yuicompress: true },files: { "bower_components/bootstrap/dist/css/bootstrap.css": "bower_components/bootstrap/less/bootstrap.less" } } },watch: { files: "bower_components/bootstrap/less/*",tasks: ["less"] } }); grunt.loadNpmtasks('grunt-contrib-less'); grunt.loadNpmtasks('grunt-contrib-watch'); };
但我之前没有尝试过使用Angular应用程序.它也可能是我做错了路由这么简单,但我已经尝试过很多次了我不知道是不是这样.
完整的东西也在github https://github.com/Lumberfella/angularApp.git上
我已经在Gruntfile.js中有一些监视代码
watch: { bower: { files: ['bower.json'],tasks: ['bowerInstall'] },js: { files: ['<%= yeoman.app %>/scripts/{,*/}*.js'],tasks: ['newer:jshint:all'],options: { livereload: true } },jsTest: { files: ['test/spec/{,tasks: ['newer:jshint:test','karma'] },styles: { files: ['<%= yeoman.app %>/styles/{,*/}*.css'],tasks: ['newer:copy:styles','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}' ] } },
并希望像(我认为不是真正的功能代码)
less: { files: [ '<%= yeoman.app %>/{,*/something.something}*.less' ] tasks: ['less:developer'] },
观看.less文件并尽可能将其制作成css文件.
解决方法
首先,我安装了grunt-contrib-less模块,并在我的样式文件夹而不是bower_components中创建了另一个bootstrap less文件夹(谢谢Mingos!).
然后我更新了Gruntfile,这就是它现在的样子:
'use strict'; // # Globbing // for performance reasons we're only matching one level down: // 'test/spec/{,*/}*.js' // use this if you want to recursively match all subfolders: // 'test/spec/**/*.js' 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); // Define the configuration for all the tasks grunt.initConfig({ // Project settings yeoman: { // configurable paths app: require('./bower.json').appPath || 'app',dist: 'dist' },less: { development: { options: { compress: true,yuicompress: true,optimization: 2 },files: { // target.css file: source.less file "app/styles/bootstrap.css": "app/styles/less/bootstrap.less" } } },// Watches files for changes and runs tasks based on the changed files watch: { bower: { files: ['bower.json'],'<%= yeoman.app %>/styles/less/{,*/}*.less'],'autoprefixer','less'] },// 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 },livereload: { options: { open: true,base: [ '.tmp','<%= yeoman.app %>' ] } },test: { options: { port: 9001,'test',dist: { options: { 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: [ '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: '{,dest: '.tmp/styles/' }] } },// Automatically inject Bower components into the app bowerInstall: { app: { src: ['<%= yeoman.app %>/index.html'],ignorePath: '<%= yeoman.app %>/' } },// Renames files for browser caching purposes rev: { dist: { files: { src: [ '<%= yeoman.dist %>/scripts/{,*/}*.js','<%= yeoman.dist %>/styles/{,'<%= yeoman.dist %>/images/{,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 %>',flow: { html: { steps: { js: ['concat','uglifyjs'],css: ['cssmin'] },post: {} } } } },// Performs rewrites based on rev and the useminPrepare configuration usemin: { html: ['<%= yeoman.dist %>/{,*/}*.html'],css: ['<%= yeoman.dist %>/styles/{,options: { assetsDirs: ['<%= yeoman.dist %>'] } },// The following *-min tasks produce minified files in the dist folder cssmin: { options: { root: '<%= yeoman.app %>' } },imagemin: { dist: { files: [{ expand: true,cwd: '<%= yeoman.app %>/images',gif}',dest: '<%= yeoman.dist %>/images' }] } },svgmin: { dist: { files: [{ expand: true,*/}*.svg',htmlmin: { dist: { options: { collapseWhitespace: true,collapseBooleanAttributes: true,removeCommentsFromCDATA: true,removeOptionalTags: true },files: [{ expand: true,cwd: '<%= yeoman.dist %>',src: ['*.html','views/{,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','images/{,*/}*.{webp}','fonts/*' ] },{ expand: true,cwd: '.tmp/images',dest: '<%= yeoman.dist %>/images',src: ['generated/*'] }] },styles: { expand: true,cwd: '<%= yeoman.app %>/styles',dest: '.tmp/styles/',*/}*.css' } },// Run some tasks in parallel to speed up the build process concurrent: { server: [ 'copy:styles' ],test: [ 'copy:styles' ],dist: [ 'copy:styles','imagemin','svgmin' ] },// 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/{,// '<%= yeoman.app %>/styles/{,*/}*.css' // ] // } // } // },// uglify: { // dist: { // files: { // '<%= yeoman.dist %>/scripts/scripts.js': [ // '<%= yeoman.dist %>/scripts/scripts.js' // ] // } // } // },// concat: { // dist: {} // },// Test settings karma: { unit: { configFile: 'karma.conf.js',singleRun: true } } }); grunt.loadNpmtasks('grunt-contrib-less'); grunt.loadNpmtasks('grunt-contrib-watch'); grunt.registerTask('serve',function (target) { if (target === 'dist') { return grunt.task.run(['build','connect:dist:keepalive']); } grunt.task.run([ 'clean:server','bowerInstall','concurrent:server','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(['serve:' + target]); }); grunt.registerTask('test',[ 'clean:server','concurrent:test','connect:test','karma' ]); grunt.registerTask('build',[ 'clean:dist','useminPrepare','concurrent:dist','concat','ngmin','copy:dist','cdnify','cssmin','uglify','rev','usemin','htmlmin' ]); grunt.registerTask('default',[ 'newer:jshint','build' ]); };
如你所见,这在我的styles文件夹中创建了一个新的bootstrap.css,然后我从我的index.html链接:)
angularjs – 从新的Yeoman安装返回的grunt返回 – 警告:找不到任务“服务”
我已经搜遍了所有但是找不到说在应用程序的根目录中运行npm install和bower install,我已经尝试但仍然是同样的错误.
我已经更新并检查了bower / grunt / npm,它们都很好.
有什么建议吗?
http://yang-wei.github.io/blog/2014/06/01/npm-install-issues-plus-angularjs-set-up/
在所有安装上运行sudo会导致主目录中的NPM文件夹出现问题.我需要通过运行以下命令来更改所有usr / local文件夹的权限:
sudo chown -R $USER /usr/local
sudo chown -R`whoami`~ / .npm
npm install -g yo grunt-cli bower
现在我再次完成这个过程,不再有错误!
以上链接似乎也是从一堆答案中拉出来的
npm throws error without sudo
angularjs – 使用grunt构建角度应用程序,app无法加载
我在Gruntfile.js中添加了一个代理,否则我认为我没有做任何事情.
知道这可能是什么原因?如何最有效地调试?我能想到的唯一方法是废除所有内容,然后激活模块,构建项目,再激活一个等等.会花很多时间.
更新
我把它缩小了.我有几个结果.如果我删除它们,则加载视图.我正在使用ui-router.这可以帮助解决这个问题吗?
.state('app',{ url: '/app',resolve: { //medias: ['MultiProductsLoader',function(ProductsLoader) { // return new ProductsLoader(); //}] },views: { 'inputView': { templateUrl: 'views/input.html',controller: 'AppCtrl' } }
UPDATE2
我的问题有点不清楚.当项目处于“开发模式”时,应用程序可以完美地工作,不受限制.但是当我构建/缩小项目时,应用程序未能在没有任何错误消息的情况下进行工作.请回答以下解决方案.
解决方法
我将此添加到Gruntfile.js中的uglify选项中
options: { report: 'min',mangle: false }
如果我找到了answear:Angular.module minification bug,你可以在这里阅读更多相关信息
我们今天的关于css – yeoman grunt构建任务和css构造的分享已经告一段落,感谢您的关注,如果您想了解更多关于angularjs – Grunt Wiredep不会在Yeoman Angular Tutorial中注册bootstrap css文件、angularjs – Yeoman Angular app,grunt watch .less files、angularjs – 从新的Yeoman安装返回的grunt返回 – 警告:找不到任务“服务”、angularjs – 使用grunt构建角度应用程序,app无法加载的相关信息,请在本站查询。
本文标签: