Created
April 22, 2022 13:53
-
-
Save MetaMmodern/ea67d46b4361baaa218d2d5f47d599e3 to your computer and use it in GitHub Desktop.
Grunt file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generated on 2014-04-18 using generator-angular 0.8.0 | |
'use strict'; | |
function enableCORP(connect, options, middlewares) { | |
middlewares.unshift(function(req, res, next) { | |
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp'); | |
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin'); | |
next(); | |
}); | |
return middlewares; | |
} | |
// # 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' | |
}, | |
// Watches files for changes and runs tasks based on the changed files | |
watch: { | |
// bower: { | |
// files: ['bower.json'], | |
// tasks: ['bowerInstall'] | |
// }, | |
js: { | |
files: ['<%= yeoman.app %>/scripts/{,*/}*.js'], | |
tasks: ['newer:jshint:all'], | |
options: { | |
livereload: true | |
} | |
}, | |
jsTest: { | |
files: ['test/spec/{,*/}*.js'], | |
tasks: ['newer:jshint:test', 'karma'] | |
}, | |
compass: { | |
files: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'], | |
tasks: ['compass:server', 'autoprefixer'], | |
options: { | |
livereload: true | |
} | |
}, | |
gruntfile: { | |
files: ['Gruntfile.js'] | |
}, | |
svgmin: { | |
files: '<%= yeoman.app %>/images/*.svg', | |
tasks: ['svgmin'] | |
}, | |
ngtemplates: { | |
files: '<%= yeoman.app %>/views/*.html', | |
tasks: ['ngtemplates'] | |
}, | |
}, | |
// The actual grunt server settings | |
connect: { | |
options: { | |
port: 9000, | |
// Change this to '0.0.0.0' to access the server from outside. | |
hostname: '0.0.0.0', | |
livereload: 35729, | |
middleware: enableCORP, | |
}, | |
test: { | |
options: { | |
port: 9001, | |
base: [ | |
'.tmp', | |
'test', | |
'<%= yeoman.app %>' | |
] | |
} | |
}, | |
dist: { | |
options: { | |
base: '<%= yeoman.dist %>' | |
} | |
}, | |
livereload: { | |
options: { | |
open: 'http://localhost:9000', | |
middleware: enableCORP, | |
base: [ | |
'.tmp', | |
'<%= yeoman.app %>' | |
] | |
} | |
}, | |
}, | |
// 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 | |
ngtemplates: { | |
options: { | |
base: '<%= yeoman.app %>', | |
module: 'depthyApp', | |
// prefix: '/', | |
htmlmin: { | |
collapseBooleanAttributes: true, | |
collapseWhitespace: true, | |
removeAttributeQuotes: true, | |
removeComments: true, // Only if you don't use comment directives! | |
removeEmptyAttributes: true, | |
removeRedundantAttributes: true, | |
removeScriptTypeAttributes: true, | |
removeStyleLinkTypeAttributes: true | |
} | |
}, | |
html: { | |
cwd: '<%= yeoman.app %>', | |
src: [ | |
'views/**/*.html', | |
'bower_components/angular-ui-bootstrap/template/modal/*.html', | |
], | |
dest: '.tmp/scripts/templates.js' | |
}, | |
uibstemplates: { | |
cwd: '<%= yeoman.app %>/bower_components/angular-ui-bootstrap', | |
src: [ | |
'template/modal/*.html', | |
], | |
dest: '.tmp/scripts/bs-templates.js' | |
}, | |
svg: { | |
options: { | |
htmlmin: {} | |
}, | |
cwd: '.tmp', | |
src: [ | |
'images/*.svg', | |
], | |
dest: '.tmp/scripts/svg-templates.js' | |
}, | |
}, | |
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 | |
bowerInstall: { | |
app: { | |
src: ['<%= yeoman.app %>/index.html'], | |
ignorePath: '<%= yeoman.app %>/' | |
}, | |
sass: { | |
src: ['<%= yeoman.app %>/styles/{,*/}*.{scss,sass}'], | |
ignorePath: '<%= yeoman.app %>/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 %>/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, | |
raw: 'Sass::Script::Number.precision = 10\n' | |
}, | |
dist: { | |
options: { | |
generatedImagesDir: '<%= yeoman.dist %>/images/generated' | |
} | |
}, | |
server: { | |
options: { | |
debugInfo: true | |
} | |
} | |
}, | |
// Renames files for browser caching purposes | |
rev: { | |
dist: { | |
files: { | |
src: [ | |
'<%= yeoman.dist %>/scripts/{,*/}*.js', | |
'<%= yeoman.dist %>/styles/{,*/}*.css', | |
// Need to comment out below line to allow html files to properly ref img src and font src | |
// '<%= 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 %>', | |
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/{,*/}*.css'], | |
options: { | |
assetsDirs: ['<%= yeoman.dist %>', '<%= yeoman.dist %>/styles'] | |
} | |
}, | |
// 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', | |
src: '{,*/}*.{png,jpg,jpeg,gif,svg}', | |
dest: '<%= yeoman.dist %>/images' | |
}] | |
} | |
}, | |
svgmin: { | |
options: { // Configuration that will be passed directly to SVGO | |
plugins: [ | |
{ mergePaths: false }, | |
] | |
}, | |
dist: { | |
files: [{ | |
expand: true, | |
cwd: '<%= yeoman.app %>/images', | |
src: '{,*/}*.svg', | |
dest: '.tmp/images' | |
}] | |
} | |
}, | |
htmlmin: { | |
dist: { | |
options: { | |
collapseWhitespace: 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: 'scripts.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,gif,jpg,txt}', | |
'.htaccess', | |
'*.html', | |
'views/{,*/}*.html', | |
'images/{,*/}*.{webp}', | |
'samples/*', | |
'styles/fonts/*', | |
'CNAME', | |
'bower_components/gif.js/dist/*.js', | |
'bower_components/whammy/whammy.js', | |
'bower_components/stats.js/build/*.js', | |
] | |
}, { | |
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', | |
'svgmin', | |
], | |
test: [ | |
'compass' | |
], | |
dist: [ | |
'compass:dist', | |
'imagemin', | |
'svgmin', | |
] | |
}, | |
uglify: { | |
options: { | |
// compress: false, | |
// preserveComments: 'all', | |
// beautify: true, | |
} | |
}, | |
// concat: { | |
// dist: {} | |
// }, | |
manifest: { | |
generate: { | |
options: { | |
basePath: '<%= yeoman.dist %>/', | |
cache: [ | |
'http://fonts.googleapis.com/css?family=Roboto+Condensed:400,700', | |
'http://www.google-analytics.com/analytics.js' | |
], | |
network: ['http://*', 'https://*', '*'], | |
// fallback: ['/ /offline.html'], | |
exclude: ['js/jquery.min.js'], | |
preferOnline: true, | |
verbose: true, | |
timestamp: true, | |
hash: true, | |
master: ['index.html'] | |
}, | |
src: [ | |
'bower_components/gif.js/dist/*.js', | |
'bower_components/whammy/whammy.js', | |
'bower_components/stats.js/build/*.js', | |
'scripts/**/*.*', | |
'styles/**/*.*', | |
'images/**/*.*', | |
'samples/*.*', | |
'icon.png', | |
'favicon.png' | |
], | |
dest: '<%= yeoman.dist %>/manifest.appcache' | |
} | |
}, | |
// Test settings | |
karma: { | |
unit: { | |
configFile: 'karma.conf.js', | |
// singleRun: true | |
} | |
} | |
}); | |
grunt.registerTask('serve', function (target) { | |
if (target === 'dist') { | |
return grunt.task.run(['build', 'connect:dist:keepalive']); | |
} | |
grunt.task.run([ | |
'clean:server', | |
// 'bowerInstall', | |
'concurrent:server', | |
'ngtemplates', | |
'autoprefixer', | |
'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', | |
'autoprefixer', | |
'connect:test', | |
'karma' | |
]); | |
grunt.registerTask('build', [ | |
'clean:dist', | |
// 'bowerInstall', | |
'useminPrepare', | |
'concurrent:dist', | |
'ngtemplates', | |
'autoprefixer', | |
'concat', | |
'ngmin', | |
'copy:dist', | |
//'cdnify', | |
'cssmin', | |
'uglify', | |
'rev', | |
'usemin', | |
'htmlmin', | |
'manifest' | |
]); | |
grunt.registerTask('default', [ | |
'newer:jshint', | |
'test', | |
'build' | |
]); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment