Created
October 19, 2015 17:29
-
-
Save kevinastone/7ffa9f9020d32ad3a120 to your computer and use it in GitHub Desktop.
Gruntfile for ES6 with babel and browserify
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
path = require 'path' | |
module.exports = (grunt) -> | |
pkg = grunt.file.readJSON('package.json') | |
nodePackages = Object.keys(pkg.dependencies or {}) | |
grunt.initConfig | |
pkg: pkg | |
root: 'theme/static' | |
assets: '<%= root %>/assets' | |
dist: '<%= root %>/dist' | |
sass: | |
dist: | |
options: | |
includePaths: require('node-refills').includePaths | |
files: | |
'<%= dist %>/css/main.css': '<%= root %>/sass/main.scss' | |
browserify: | |
modules: | |
options: | |
require: nodePackages | |
files: | |
'<%= dist %>/js/modules.js': [] | |
apps: | |
options: | |
transform: ['babelify'] | |
exclude: nodePackages | |
files: [ | |
expand: true | |
src: ['**/app.js'] | |
dest: '<%= dist %>/js' | |
cwd: '<%= root %>/js' | |
rename: (dest, srcPath) -> | |
# Rename from something/app.js -> something.js | |
filename = srcPath.replace /^(.*\/)?([^\/]+?)\/app.js$/, '$1$2.js' | |
console.log filename | |
path.join(dest, filename) | |
] | |
uglify: | |
options: | |
sourceMap: true | |
dist: | |
files: [ | |
expand: true | |
cwd: '<%= dist %>/js' | |
src: ['**/*.js'] | |
dest: '<%= dist %>/js' | |
ext: '.min.js' | |
extDot: 'last' | |
# Don't re-minimize already minimized files | |
filter: (filename) -> | |
not /.min.js$/.test filename | |
] | |
watch: | |
options: | |
atBegin: true | |
sass: | |
files: [ | |
"<%= root %>/sass/**/*.scss" | |
] | |
tasks: ['sass'] | |
js: | |
files: [ | |
"<%= root %>/js/**/*.js" | |
] | |
tasks: ['browserify:apps'] | |
clean: | |
dist: ['<%= dist %>'] | |
require('load-grunt-tasks')(grunt) | |
grunt.registerTask 'js', [ | |
'browserify', | |
'uglify', | |
] | |
grunt.registerTask 'build', [ | |
'sass', | |
'js' | |
] | |
grunt.registerTask 'default', ['build'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment