Skip to content

Instantly share code, notes, and snippets.

@n1n9-jp
Last active September 17, 2017 03:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n1n9-jp/ff1f48c09174c5311d21429ac2598887 to your computer and use it in GitHub Desktop.
Save n1n9-jp/ff1f48c09174c5311d21429ac2598887 to your computer and use it in GitHub Desktop.
setting example of compile html, css & javascript files.
module.exports = function(grunt){
var pkg = grunt.file.readJSON( 'package.json' );
grunt.initConfig({
pkg: pkg,
clean: {
build: [ '.tmp', 'dest' ],
release: [ '.tmp' ]
},
copy: {
html: {
files: [ {
expand: true,
cwd: 'src',
src: [
'*.html',
'assets/css/lib/*.*',
'assets/js/lib/*.*',
'assets/data/*.*',
'assets/img/*.*'
],
dest: 'dest'
} ]
}
},
useminPrepare: {
html: 'src/*.html',
options: {
dest:'dest'
}
},
usemin: {
html: 'dest/*.html',
options: {
dest: 'dest'
}
},
htmlmin: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: {
src: 'dest/index.html',
dest: 'dest/dest.html'
}
},
watch: {
scripts: {
files: [ 'src/assets/css/*.css', 'src/assets/js/*.js' ],
tasks: [ 'build' ]
}
}
});
Object.keys( pkg.devDependencies ).forEach( function( devDependency ) {
if( devDependency.match( /^grunt\-/ ) ) {
grunt.loadNpmTasks( devDependency );
}
} );
grunt.registerTask( 'build', [
'clean:build',
'copy',
'useminPrepare',
'concat',
'uglify',
'cssmin',
'htmlmin',
'usemin',
'clean:release'
] );
grunt.registerTask( 'default', [ 'watch' ] );
}
{
"name": "repository_name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"grunt": "^1.0.1",
"grunt-contrib-clean": "^1.1.0",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-cssmin": "^2.2.1",
"grunt-contrib-htmlmin": "^2.4.0",
"grunt-contrib-uglify": "^3.1.0",
"grunt-usemin": "^3.1.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment