Just installed a new and fresh angularJS application based on Yeoman's generator-cg-angular. After typing grunt serve I have the normal following stack:
$ grunt serve
Running "dom_munger:read" (dom_munger) task
Processing index.html
Wrote script[data-concat!="false"].src to dom_munger.data.appjs
Wrote link[rel="stylesheet"][data-concat!="false"].href to dom_munger.data.appcss
Running "jshint:main" (jshint) task
>> 5 files lint free.
Running "connect:main" (connect) task
Started connect web server on http://localhost:9001
Running "watch" task
Waiting...
You can see that my problem is with the "watch" task. I had a yeoman's generator-angular project that always worked as expected when I called grunt servewith it but now with generator-cg-angular, this one call doesn't work.
Note that grunt build and grunt test work perfectly. Only have problem with the grunt serve command.
Here is my Gruntfile.js content if someone can pin point the problem.
I'm assuming the problem starts on this line: grunt.event.on('watch',... but have no clue how to resolve it.
/*jslint node: true */
'use strict';
var pkg = require('./package.json');
//Using exclusion patterns slows down Grunt significantly
//instead of creating a set of patterns like '**/*.js' and '!**/node_modules/**'
//this method is used to create a set of inclusive patterns for all subdirectories
//skipping node_modules, bower_components, dist, and any .dirs
//This enables users to create any directory structure they desire.
var createFolderGlobs = function(fileTypePatterns) {
fileTypePatterns = Array.isArray(fileTypePatterns) ? fileTypePatterns : [fileTypePatterns];
var ignore = ['node_modules','bower_components','dist','temp'];
var fs = require('fs');
return fs.readdirSync(process.cwd())
.map(function(file){
if (ignore.indexOf(file) !== -1 ||
file.indexOf('.') === 0 ||
!fs.lstatSync(file).isDirectory()) {
return null;
} else {
return fileTypePatterns.map(function(pattern) {
return file + '/**/' + pattern;
});
}
})
.filter(function(patterns){
return patterns;
})
.concat(fileTypePatterns);
};
module.exports = function (grunt) {
// load all grunt tasks
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
connect: {
main: {
options: {
port: 9001
}
}
},
watch: {
main: {
options: {
livereload: true,
livereloadOnError: false,
spawn: false
},
files: [createFolderGlobs(['*.js','*.less','*.html']),'!_SpecRunner.html','!.grunt'],
tasks: [] //all the tasks are run dynamically during the watch event handler
}
},
jshint: {
main: {
options: {
jshintrc: '.jshintrc'
},
src: createFolderGlobs('*.js')
}
},
clean: {
before:{
src:['dist','temp']
},
after: {
src:['temp']
}
},
less: {
production: {
options: {
},
files: {
'temp/app.css': 'app.less'
}
}
},
ngtemplates: {
main: {
options: {
module: pkg.name,
htmlmin:'<%= htmlmin.main.options %>'
},
src: [createFolderGlobs('*.html'),'!index.html','!_SpecRunner.html'],
dest: 'temp/templates.js'
}
},
copy: {
main: {
files: [
{src: ['img/**'], dest: 'dist/'},
{src: ['bower_components/font-awesome/fonts/**'], dest: 'dist/',filter:'isFile',expand:true}
//{src: ['bower_components/angular-ui-utils/ui-utils-ieshiv.min.js'], dest: 'dist/'},
//{src: ['bower_components/select2/*.png','bower_components/select2/*.gif'], dest:'dist/css/',flatten:true,expand:true},
//{src: ['bower_components/angular-mocks/angular-mocks.js'], dest: 'dist/'}
]
}
},
dom_munger:{
read: {
options: {
read:[
{selector:'script[data-concat!="false"]',attribute:'src',writeto:'appjs'},
{selector:'link[rel="stylesheet"][data-concat!="false"]',attribute:'href',writeto:'appcss'}
]
},
src: 'index.html'
},
update: {
options: {
remove: ['script[data-remove!="false"]','link[data-remove!="false"]'],
append: [
{selector:'body',html:'<script src="app.full.min.js"></script>'},
{selector:'head',html:'<link rel="stylesheet" href="app.full.min.css">'}
]
},
src:'index.html',
dest: 'dist/index.html'
}
},
cssmin: {
main: {
src:['temp/app.css','<%= dom_munger.data.appcss %>'],
dest:'dist/app.full.min.css'
}
},
concat: {
main: {
src: ['<%= dom_munger.data.appjs %>','<%= ngtemplates.main.dest %>'],
dest: 'temp/app.full.js'
}
},
ngmin: {
main: {
src:'temp/app.full.js',
dest: 'temp/app.full.js'
}
},
uglify: {
main: {
src: 'temp/app.full.js',
dest:'dist/app.full.min.js'
}
},
htmlmin: {
main: {
options: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
},
files: {
'dist/index.html': 'dist/index.html'
}
}
},
imagemin: {
main:{
files: [{
expand: true, cwd:'dist/',
src:['**/{*.png,*.jpg}'],
dest: 'dist/'
}]
}
},
karma: {
options: {
frameworks: ['jasmine'],
files: [ //this files data is also updated in the watch handler, if updated change there too
'<%= dom_munger.data.appjs %>',
'bower_components/angular-mocks/angular-mocks.js',
createFolderGlobs('*-spec.js')
],
logLevel:'ERROR',
reporters:['mocha'],
autoWatch: false, //watching is handled by grunt-contrib-watch
singleRun: true
},
all_tests: {
browsers: ['PhantomJS','Chrome','Firefox']
},
during_watch: {
browsers: ['PhantomJS']
},
}
});
grunt.registerTask('build',['jshint','clean:before','less','dom_munger','ngtemplates','cssmin','concat','ngmin','uglify','copy','htmlmin','imagemin','clean:after']);
grunt.registerTask('serve', ['dom_munger:read','jshint','connect', 'watch']);
grunt.registerTask('test',['dom_munger:read','karma:all_tests']);
grunt.event.on('watch', function(action, filepath) {
//https://github.com/gruntjs/grunt-contrib-watch/issues/156
var tasksToRun = [];
if (filepath.lastIndexOf('.js') !== -1 && filepath.lastIndexOf('.js') === filepath.length - 3) {
//lint the changed js file
grunt.config('jshint.main.src', filepath);
tasksToRun.push('jshint');
//find the appropriate unit test for the changed file
var spec = filepath;
if (filepath.lastIndexOf('-spec.js') === -1 || filepath.lastIndexOf('-spec.js') !== filepath.length - 8) {
spec = filepath.substring(0,filepath.length - 3) + '-spec.js';
}
//if the spec exists then lets run it
if (grunt.file.exists(spec)) {
var files = [].concat(grunt.config('dom_munger.data.appjs'));
files.push('bower_components/angular-mocks/angular-mocks.js');
files.push(spec);
grunt.config('karma.options.files', files);
tasksToRun.push('karma:during_watch');
}
}
//if index.html changed, we need to reread the <script> tags so our next run of karma
//will have the correct environment
if (filepath === 'index.html') {
tasksToRun.push('dom_munger:read');
}
grunt.config('watch.main.tasks',tasksToRun);
});
};
Thanks for your help.
Related
I am currently using Angular Bootstrap Colorpicker (https://github.com/buberdds/angular-bootstrap-colorpicker)
It works fine when I run it locally. However when I use Grunt to build the files, the colorpicker stop working. It does not throw any errors but it does not do anything when the user click the colorpicker.
I attach the Gruntfile.js:
// Project configuration.
grunt.initConfig({
connect: {
main: {
options: {
port: 9001
}
}
},
watch: {
main: {
options: {
livereload: true,
livereloadOnError: false,
spawn: false
},
files: [createFolderGlobs(['*.js', '*.less', '*.html']), '!_SpecRunner.html', '!.grunt'],
tasks: [] //all the tasks are run dynamically during the watch event handler
}
},
jshint: {
main: {
options: {
jshintrc: '.jshintrc'
},
src: createFolderGlobs('*.js')
}
},
clean: {
before: {
src: ['dist', 'temp']
},
after: {
src: ['temp']
}
},
less: {
production: {
options: {
},
files: {
'temp/app.css': 'app.less'
}
}
},
ngtemplates: {
main: {
options: {
module: pkg.name,
htmlmin: '<%= htmlmin.main.options %>'
},
src: [createFolderGlobs('*.html'), '!index.html', '!_SpecRunner.html'],
dest: 'temp/templates.js'
}
},
copy: {
main: {
files: [
{ src: ['img/**'], dest: 'dist/' },
{ src: ['bower_components/font-awesome/fonts/**'], dest: 'dist/', filter: 'isFile', expand: true },
{ src: ['bower_components/bootstrap/fonts/**'], dest: 'dist/', filter: 'isFile', expand: true },
{ src: ['deploy.json'], dest: 'dist/', filter: 'isFile', expand: true },
{ src: ['common/font/**'], dest: 'dist/', filter: 'isFile', expand: true }
]
}
},
dom_munger: {
read: {
options: {
read: [
{ selector: 'script[data-concat!="false"]', attribute: 'src', writeto: 'appjs' },
{ selector: 'link[rel="stylesheet"][data-concat!="false"]', attribute: 'href', writeto: 'appcss' }
]
},
src: 'index.html'
},
update: {
options: {
remove: ['script[data-remove!="false"]', 'link[data-remove!="false"]'],
append: [
{ selector: 'body', html: '<script src="app.full.js"></script>' },
{ selector: 'head', html: '<link rel="stylesheet" href="app.full.min.css">' }
]
},
src: 'index.html',
dest: 'dist/index.html'
}
},
cssmin: {
main: {
src: ['temp/app.css', '<%= dom_munger.data.appcss %>'],
dest: 'dist/app.full.min.css'
}
},
concat: {
main: {
src: ['<%= dom_munger.data.appjs %>', '<%= ngtemplates.main.dest %>'],
dest: 'temp/app.full.js'
}
},
ngAnnotate: {
main: {
src: 'temp/app.full.js',
dest: 'dist/app.full.js'
}
},
uglify: {
main: {
src: 'temp/app.full.js',
dest: 'dist/app.full.min.js'
}
},
htmlmin: {
main: {
options: {
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true
},
files: {
'dist/index.html': 'dist/index.html'
}
}
}
Any help will be appreciated. Thank you!
Lets inspect your Build to see whats the grunt retrieves to us.
When you build put these 2 parameters --debug and --stack
I had the same problem.
I suppose you have in the index.html a link to the css and to the module, something like:
link rel="stylesheet" href="../bower_components/angular-bootstrap-colorpicker/css/colorpicker.min.css"
and
script src="../bower_components/angular-bootstrap-colorpicker/js/bootstrap-colorpicker-module.min.js"
Indeed, the minified versions don't work properly. That is why I removed ".min" from index.html and bound normal size files:
link rel="stylesheet" href="../bower_components/angular-bootstrap-colorpicker/css/colorpicker.css"
and
script src="../bower_components/angular-bootstrap-colorpicker/js/bootstrap-colorpicker-module.js"
Nothing else and it worked for me.
I am creating an angular app with grunt/yeoman and trying to create a public version with minified files. The problem is that no js files and css is created:
// Generated on 2015-06-01 using generator-angular 0.10.0
'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);
// Configurable paths for the application
var appConfig = {
app: require('./bower.json').appPath || 'app',
dist: 'dist'
};
// Define the configuration for all the tasks
grunt.initConfig({
// Watches files for changes and runs tasks based on the changed files
watch: {
bower: {
files: ['bower.json'],
tasks: ['wiredep']
},
js: {
files: ['app/{,*/}*.js','app/**/*.json'],
tasks: ['newer:jshint:all'],
options: {
livereload: '<%= connect.options.livereload %>'
}
},
jsTest: {
files: ['test/spec/{,*/}*.js'],
tasks: ['newer:jshint:test', 'karma']
},
compass: {
files: ['app/styles/{,*/}*.{scss,sass}'],
tasks: ['compass:server', 'autoprefixer']
},
gruntfile: {
files: ['Gruntfile.js']
},
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: [
'app/**/*.html',
'app/**/*.js',
'app/**/*.json',
'.tmp/styles/{,*/}*.css',
'app/styles/{,*/}*.css',
'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
},
livereload: {
options: {
open: true,
middleware: function (connect) {
return [
connect.static('.tmp'),
connect().use(
'/bower_components',
connect.static('./bower_components')
),
connect.static(appConfig.app)
];
}
}
},
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: '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',
'app/scripts_old/{,*/}*.js'
]
},
test: {
options: {
jshintrc: 'test/.jshintrc'
},
src: ['test/spec/{,*/}*.js']
}
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'.tmp',
'dist/{,*/}*',
'!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: {
app: {
src: ['app/index.html'],
ignorePath: /\.\.\//
},
sass: {
src: ['app/styles/{,*/}*.{scss,sass}'],
ignorePath: /(\.\.\/){1,2}bower_components\//
}
},
// Compiles Sass to CSS and generates necessary files if requested
compass: {
options: {
sassDir: 'app/styles',
cssDir: '.tmp/styles',
generatedImagesDir: '.tmp/images/generated',
imagesDir: 'app/images',
javascriptsDir: 'app/scripts_old',
fontsDir: 'app/styles/fonts',
importPath: './bower_components',
httpImagesPath: '/images',
httpGeneratedImagesPath: '/images/generated',
httpFontsPath: '/styles/fonts',
relativeAssets: false,
assetCacheBuster: false,
raw: 'Sass::Script::Number.precision = 10\n'
},
dist: {
options: {
generatedImagesDir: 'dist/images/generated'
}
},
server: {
options: {
debugInfo: true
}
}
},
// Renames files for browser caching purposes
filerev: {
dist: {
src: [
'dist/scripts_old/{,*/}*.js',
'dist/styles/{,*/}*.css',
'dist/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}',
'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: 'app/index.html',
options: {
dest: 'dist',
flow: {
html: {
steps: {
js: ['concat', 'uglifyjs'],
css: ['cssmin']
},
post: {}
}
}
}
},
// Performs rewrites based on filerev and the useminPrepare configuration
usemin: {
html: ['dist/{,*/}*.html'],
css: ['dist/styles/{,*/}*.css'],
js: ['dist/scripts/{,*/}*.js'],
options: {
assetsDirs: [
'dist',
'dist/images',
'dist/styles'
],
patterns: {
js: [[/(images\/[^''""]*\.(png|jpg|jpeg|gif|webp|svg))/g, 'Replacing references to 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: {
'dist/styles/main.css': [
'.tmp/styles/{,*/}*.css'
]
}
}
},
uglify: {
dist: {
files: {
'dist/scripts/scripts.js': [
'dist/scripts/scripts.js'
]
}
}
},
concat: {
dist: {}
},
imagemin: {
dist: {
files: [{
expand: true,
cwd: 'app/images',
src: '{,*/}*.{png,jpg,jpeg,gif}',
dest: 'dist/images'
}]
}
},
svgmin: {
dist: {
files: [{
expand: true,
cwd: 'app/images',
src: '{,*/}*.svg',
dest: 'dist/images'
}]
}
},
htmlmin: {
dist: {
options: {
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeCommentsFromCDATA: true,
removeOptionalTags: true
},
files: [{
expand: true,
cwd: 'dist',
src: ['*.html', 'views/{,*/}*.html'],
dest: 'dist'
}]
}
},
// ng-annotate tries to make the code safe for minification automatically
// by using the Angular long form for dependency injection.
ngAnnotate: {
dist: {
files: [{
expand: true,
cwd: '.tmp/concat/scripts',
src: ['*.js', '!oldieshim.js'],
dest: '.tmp/concat/scripts'
}]
}
},
// Replace Google CDN references
cdnify: {
dist: {
html: ['dist/*.html']
}
},
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: 'app',
dest: 'dist',
src: [
'*.{ico,png,txt}',
'.htaccess',
'modules/**.*.js',
'*.html',
'views/{,*/}*.html',
'images/{,*/}*.{webp}',
'fonts/{,*/}*.*'
]
}, {
expand: true,
cwd: '.tmp/images',
dest: 'dist/images',
src: ['generated/*']
}, {
expand: true,
cwd: '.',
src: 'bower_components/bootstrap-sass-official/assets/fonts/bootstrap/*',
dest: 'dist'
}]
},
styles: {
expand: true,
cwd: '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
}
},
protractor: {
options: {
keepAlive: true,
configFile: "test/protractor.conf.js"
},
run: {}
}
});
grunt.registerTask('serve', 'Compile then start a connect web server', function (target) {
grunt.log.warn('running grunt serve , value of target',target);
if (target === 'dist') {
grunt.log.warn('target = dist');
return grunt.task.run(['build', 'connect:dist:keepalive']);
}
grunt.task.run([
'clean:server',
'wiredep',
'test',
//'concurrent:server',
'autoprefixer',
'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.loadNpmTasks("grunt-protractor-runner");
grunt.registerTask('test', [
'clean:server',
//'concurrent:test',
'autoprefixer',
'connect:test',
'karma'
//'protractor:run'
]);
grunt.registerTask('build', [
'clean:dist',
'wiredep',
//'useminPrepare',
//'concurrent:dist',
'autoprefixer',
'concat',
'ngAnnotate',
'copy:dist',
//'cdnify',
'cssmin',
'uglify',
'filerev',
'usemin',
'htmlmin'
]);
grunt.registerTask('default', [
'newer:jshint',
'test',
'build'
]);
};
The directory structure looks like this:
app/modules/
styles
commone///partials
When I run grunt build I get:
Loading "imagemin.js" tasks...ERROR
>> Error: Cannot find module 'imagemin-gifsicle'
>> Local Npm module "grunt-google-cdn" not found. Is it installed?
Running "clean:dist" (clean) task
Cleaning dist/.htaccess...OK
Cleaning dist/404.html...OK
Cleaning dist/bower_components...OK
Cleaning dist/index.html...OK
Cleaning dist/robots.txt...OK
Running "wiredep:app" (wiredep) task
Running "wiredep:sass" (wiredep) task
Running "autoprefixer:dist" (autoprefixer) task
Running "concat:dist" (concat) task
Running "ngAnnotate:dist" (ngAnnotate) task
>> No files provided to the ngAnnotate task.
Running "copy:dist" (copy) task
Copied 9 files
Running "cssmin:dist" (cssmin) task
>> Destination not written because minified CSS was empty.
Running "uglify:dist" (uglify) task
>> Destination dist/scripts/scripts.js not written because src files were empty.
Running "filerev:dist" (filerev) task
Running "usemin:html" (usemin) task
Replaced 2 references to assets
Running "usemin:css" (usemin) task
Replaced 0 references to assets
Running "usemin:js" (usemin) task
Replaced 0 references to assets
Running "htmlmin:dist" (htmlmin) task
Minified dist/404.html 3.53 kB → 3.39 kB
Minified dist/index.html 1.16 kB → 1.07 kB
Done, without errors.
How can I generate css and js files?
Could you please ensure that you do have correct source file mapped in uglify configuration.As per your current above pasted script the src and destination both files are with same name.
uglify: {
dist: {
files: {
'dist/scripts/scripts.js': [
'dist/scripts/scripts.js'
]
}
}
}
You can go through with this for more information. Initially try to make it work with simple configuration like this :
uglify: {
dist: {
files: {'dest/b.js': ['src/bb.js', 'src/bbb.js']}
}
}
How does the htmlmin task work see here. and for where are those files located in the dist folder see below
htmlmin: {
dist: {
options: {
collapseWhitespace: true,
conservativeCollapse: true,
collapseBooleanAttributes: true,
removeCommentsFromCDATA: true,
removeOptionalTags: true
},
files: [{
expand: true,
cwd: 'dist',
src: ['*.html', 'views/{,*/}*.html'],
dest: 'dist'
}]
}
}
I'd like Protractor E2E tests to reflect my code coverage in SonarQube.
I've tried grunt-protractor-coverage npm module but it shows 100% coverage while the report file it creates is empty.
Here's the relevant part of my Gruntfile.js:
connect: {
options: {
port: 9000,
hostname: 'localhost'
},
runtime: {
options: {
base: 'instrumented/build'
}
}
},
instrument: {
files: 'build/**/*.js',
options: {
lazy: true,
basePath: "instrumented"
}
},
protractor_coverage: {
options: {
keepAlive: true,
noColor: false,
coverageDir: 'coverage',
args: {
baseUrl: 'http://localhost:9000'
}
},
local: {
options: {
configFile: './protractor-chrome-conf.js'
}
}
},
makeReport: {
src: 'coverage/*.json',
options: {
type: 'lcov',
dir: 'coverage/dir',
print: 'detail'
}
}
Any ideas?
You must first install the SonarJS code analyzer
And then this plugin can be fed with a LCOV report providing the coverage information: http://docs.sonarqube.org/display/PLUG/JavaScript+Coverage+Results+Import
I have an Angular app and I'm using Grunt, I made my Gruntfile for min, uglify and concat and after I reference my new .js file (created with Grunt) in my main.html everything is working fine when I publish my project. However, when I want to make some changes and want to run my app in debug mode, I have to change my .js references again in my main.html. Is there a way to check if in what mode my app is running, so I can load the specific .js files?
I've seen how to accomplish this in ASP.net, but how can I solve it in my case?
Below is my gruntfile.js
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
clean: {
options: {force: true},
all: {
src: ['../Analaysis.UI/app_built/**/*.*']
}
},
ngmin: {
all: {
files: [
{
expand: true,
cwd: '../Analaysis.UI',
src: ['**/*.js'
, '!**/Scripts/*'
, '!**/Scripts/**/*'
, '!**/obj/*'
, '!**/obj/**/*'
, '!**/src/**/**/*'],
dest: '../Analaysis.UI/app_built/',
ext: '.js'
}
]
}
},
uglify: {
all: {
files: [
{
expand: true,
cwd: '../Analaysis.UI/app_built',
src: ['**/*.js'],
dest: '../Analaysis.UI/app_built/',
ext: '.min.js'
}
]
}
},
concat: {
js: {
options: {
separator: ';'
},
src: ['../Analaysis.UI/app_built/Global/global.min.js'
,'../Analaysis.UI/app_built/Global/config.min.js'
,'../Analaysis.UI/app_built/Global/GlobalService.min.js'
,'../Analaysis.UI/app_built/Login/LoginController.min.js'
,'../Analaysis.UI/app_built/Login/LoginService.min.js'],
dest: '../Analaysis.UI/app_built/app_built_login.js'
}
}
});
grunt.registerTask("default", ['build']);
grunt.registerTask('build', ['clean', 'ngmin', 'uglify', 'concat']);
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-ngmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
};
For each type of build, you would require a different configuration.
Check below code.
'use strict';
module.exports = function (grunt) {
grunt.initConfig({
uglify: {
all: {
files: [
{
expand: true,
cwd: '../Analaysis.UI/app_built',
src: ['**/*.js'],
dest: '../Analaysis.UI/app_built/',
ext: '.min.js'
}
]
},
prod: {
files: [
{
expand: true,
cwd: '../Analaysis.UI/app_built',
src: ['**/*.js'],
dest: 'prod/Analaysis.UI/app_built/',//You can have different path according to build type
ext: '.min.js'
}
]
}
},
concat: {
js: {
options: {
separator: ';'
},
src: ['../Analaysis.UI/app_built/Global/global.min.js'
, '../Analaysis.UI/app_built/Global/config.min.js'
, '../Analaysis.UI/app_built/Global/GlobalService.min.js'
, '../Analaysis.UI/app_built/Login/LoginController.min.js'
, '../Analaysis.UI/app_built/Login/LoginService.min.js'],
dest: '../Analaysis.UI/app_built/app_built_login.js'
},
prod: {
options: {
separator: ';'
},
src: ['../Analaysis.UI/app_built/Global/global.min.js'
, '../Analaysis.UI/app_built/Global/config.min.js'
, '../Analaysis.UI/app_built/Global/GlobalService.min.js'
, '../Analaysis.UI/app_built/Login/LoginController.min.js'
, '../Analaysis.UI/app_built/Login/LoginService.min.js'],
dest: 'production/Analaysis.UI/app_built/app_built_login.js'
}
}
});
grunt.registerTask("default", ['build']);
grunt.registerTask('build', ['uglify', 'concat']);
//Task according to build. run "grunt debug" for debug build
grunt.registerTask('debug', ['uglify:all', 'concat:js']);
grunt.registerTask('prod', ['uglify:prod', 'concat:prod']);
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-concat');
};
I am having a backbone project in yeoman and below is my grunt file configuration
module.exports = function( grunt ) {
'use strict';
//
// Grunt configuration:
//
// https://github.com/cowboy/grunt/blob/master/docs/getting_started.md
//
grunt.initConfig({
// Project configuration
// ---------------------
// specify an alternate install location for Bower
bower: {
dir: 'app/scripts/vendor'
},
// Coffee to JS compilation
coffee: {
dist: {
src: 'app/scripts/**/*.coffee',
dest: 'app/scripts'
}
},
// compile .scss/.sass to .css using Compass
compass: {
dist: {
// http://compass-style.org/help/tutorials/configuration-reference/#configuration-properties
require: ['susy'],
options: {
css_dir: 'temp/styles',
sass_dir: 'app/styles',
images_dir: 'app/images',
javascripts_dir: 'temp/scripts',
force: true
}
}
},
// generate application cache manifest
manifest:{
dest: ''
},
// headless testing through PhantomJS
mocha: {
all: ['test/**/*.html']
},
// default watch configuration
watch: {
coffee: {
files: '<config:coffee.dist.src>',
tasks: 'coffee reload'
},
compass: {
files: [
'app/styles/**/*.{scss,sass}'
],
tasks: 'compass reload'
},
reload: {
files: [
'app/*.html',
'app/styles/**/*.css',
'app/scripts/**/*.js',
'app/images/**/*'
],
tasks: 'reload'
}
},
// default lint configuration, change this to match your setup:
// https://github.com/cowboy/grunt/blob/master/docs/task_lint.md#lint-built-in-task
lint: {
files: [
'Gruntfile.js',
'app/scripts/**/*.js',
'spec/**/*.js'
]
},
// specifying JSHint options and globals
// https://github.com/cowboy/grunt/blob/master/docs/task_lint.md#specifying-jshint-options-and-globals
jshint: {
options: {
curly: true,
eqeqeq: true,
immed: true,
latedef: true,
newcap: true,
noarg: true,
sub: true,
undef: true,
boss: true,
eqnull: true,
browser: true
},
globals: {
jQuery: true
}
},
// Build configuration
// -------------------
// the staging directory used during the process
staging: 'temp',
// final build output
output: 'dist',
mkdirs: {
staging: 'app/'
},
// Below, all paths are relative to the staging directory, which is a copy
// of the app/ directory. Any .gitignore, .ignore and .buildignore file
// that might appear in the app/ tree are used to ignore these values
// during the copy process.
// concat css/**/*.css files, inline #import, output a single minified css
css: {
'styles/main.css': ['styles/**/*.css']
},
// renames JS/CSS to prepend a hash of their contents for easier
// versioning
rev: {
js: 'scripts/**/*.js',
css: 'styles/**/*.css',
img: 'images/**'
},
// usemin handler should point to the file containing
// the usemin blocks to be parsed
'usemin-handler': {
html: 'index.html'
},
// update references in HTML/CSS to revved files
usemin: {
html: ['**/*.html'],
css: ['**/*.css']
},
// HTML minification
html: {
files: ['**/*.html']
},
// Optimizes JPGs and PNGs (with jpegtran & optipng)
img: {
dist: '<config:rev.img>'
},
// rjs configuration. You don't necessarily need to specify the typical
// `path` configuration, the rjs task will parse these values from your
// main module, using http://requirejs.org/docs/optimization.html#mainConfigFile
//
// name / out / mainConfig file should be used. You can let it blank if
// you're using usemin-handler to parse rjs config from markup (default
// setup)
rjs: {
// no minification, is done by the min task
optimize: 'none',
baseUrl: './scripts',
wrap: true,
name:'config',
}//,
// While Yeoman handles concat/min when using
// usemin blocks, you can still use them manually
//concat: {
//dist: ''
//},
//min: {
// dist: ''
// }
});
// Alias the `test` task to run the `mocha` task instead
grunt.registerTask('test', 'mocha');
};
I have tried to build this , even though build was a success i am not getting the bacbone models and views on the minified app-amd.js file
Can i get any pointers on this?
Try using the latest backbone generator with Yeoman 1.0beta. We have made lots of improvements to it.
If you are still facing the same issue, please raise a ticket on github.