Last active
September 17, 2017 03:46
-
-
Save n1n9-jp/ff1f48c09174c5311d21429ac2598887 to your computer and use it in GitHub Desktop.
setting example of compile html, css & javascript files.
This file contains 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
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' ] ); | |
} |
This file contains 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
{ | |
"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