Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var path = require('path');
- module.exports = function (grunt) {
- // configure the tasks
- grunt.initConfig({
- useminPrepare: {
- html: 'build/index.html',
- options: {
- root: 'build',
- dest: 'build',
- flow: {
- steps: {
- js: [
- 'concat',
- {
- name: 'ngAnnotate',
- createConfig: function (context, block) {
- var cfg = {
- files: []
- };
- context.outFiles = [];
- // Depending whether or not we're the last of the step we're not going to output the same thing:
- // if we're the last one we must use the block dest file name for output
- // otherwise uglify each input file into its given outputfile
- if (context.last === true) {
- var files = {};
- var ofile = path.join(context.outDir, block.dest);
- files.dest = ofile;
- files.src = context.inFiles.map(function (fname) {
- return path.join(context.inDir, fname);
- });
- // cfg[ofile] = context.inFiles.map(function (fname) { return path.join(context.inDir, fname);});
- cfg.files.push(files);
- context.outFiles.push(block.dest);
- } else {
- context.inFiles.forEach(function (fname) {
- var file = path.join(context.inDir, fname);
- var outfile = path.join(context.outDir, fname);
- cfg.files.push({
- src: [file],
- dest: outfile
- });
- // cfg[outfile] = [file];
- context.outFiles.push(fname);
- });
- }
- return cfg;
- }
- },
- 'uglifyjs'
- ],
- css: [ 'concat', 'cssmin' ]
- },
- post: {
- js: [{
- name: 'uglify',
- createConfig: function (context) {
- context.options.generated.options = {preserveComments: 'some'};
- }
- }, {
- name: 'ngAnnotate',
- createConfig: function (context) {
- context.options.generated.options = {singleQuotes: true};
- }
- }]
- }
- }
- }
- },
- processhtml: {
- build: {
- files: {
- 'build/index.html': ['build/index.html']
- }
- },
- options: {
- data: {
- path: '/',
- gacode: 'UA-2328122-20'
- },
- commentMarker: 'process'
- }
- },
- usemin: {
- html: 'build/index.html',
- options: {
- root: 'build',
- dest: 'build'
- }
- },
- copy: {
- build: {
- files: [
- {
- expand: true,
- cwd: 'client/bower_components/ckeditor',
- src: ['**'],
- dest: 'client/lib/ckeditor'
- },
- {
- expand: true,
- cwd: 'client/',
- src: [ '**' ],
- dest: 'build'
- },
- {
- expand: true,
- cwd: 'client/bower_components/bootstrap/dist',
- src: [ 'fonts', 'fonts/**' ],
- dest: 'build',
- }
- ]
- }
- },
- clean: {
- build: {
- src: [ 'build' ]
- },
- stylesheets: {
- src: [ 'build/**/*.css', '!build/css/optimized.css', '!build/lib/**' ]
- },
- scripts: {
- src: [ 'build/js/controllers', 'build/js/services', 'build/js/directives', 'build/**/*.js', '!build/js/*-optimized.js', '!build/lib/**' ]
- },
- other: {
- src: [ 'build/bower_components', '.tmp', 'build/bower.json' ]
- }
- },
- loopback_angular: {
- services: {
- options: {
- input: 'server/app.js',
- output: 'client/js/services/lb-services.js'
- }
- }
- },
- watch: {
- assets: {
- files: [ 'client/**/*.css', 'client/**/*.js', 'client/index.html'],
- tasks: [ 'copy', 'processhtml', 'assets' ]
- },
- services: {
- files: [ 'server/models.json', 'server/models/*.*' ],
- tasks: [ 'services' ]
- },
- copy: {
- files: [ 'client/**', '!client/**/*.css', '!client/**/*.js', '!client/index.html' ],
- tasks: [ 'copy', 'processhtml' ]
- }
- }
- });
- // load the tasks
- grunt.loadNpmTasks('grunt-contrib-copy');
- grunt.loadNpmTasks('grunt-contrib-concat');
- grunt.loadNpmTasks('grunt-contrib-clean');
- grunt.loadNpmTasks('grunt-contrib-cssmin');
- grunt.loadNpmTasks('grunt-contrib-uglify');
- grunt.loadNpmTasks('grunt-contrib-watch');
- grunt.loadNpmTasks('grunt-loopback-angular');
- grunt.loadNpmTasks('grunt-usemin');
- grunt.loadNpmTasks('grunt-processhtml');
- grunt.loadNpmTasks('grunt-ng-annotate');
- // define the tasks
- grunt.registerTask(
- 'default',
- 'Watches the project for changes, automatically builds them.',
- [ 'build', 'watch' ]
- );
- grunt.registerTask(
- 'services',
- [ 'loopback_angular' ]
- );
- grunt.registerTask(
- 'assets',
- 'Compiles the scripts stylesheets.',
- [ 'useminPrepare', 'concat', 'cssmin', 'ngAnnotate', 'uglify', 'usemin', 'clean:other', 'clean:stylesheets', 'clean:scripts' ]
- );
- grunt.registerTask(
- 'build',
- 'Compiles all of the assets and copies the files to the build directory.',
- [ 'services', 'clean:build', 'copy', 'processhtml', 'assets' ]
- );
- };
Advertisement
Add Comment
Please, Sign In to add comment