Skip to content

Instantly share code, notes, and snippets.

@SethVandebrooke
Last active February 4, 2019 20:52
Show Gist options
  • Save SethVandebrooke/439d8eda54d4b38614869f3bcf9f7f46 to your computer and use it in GitHub Desktop.
Save SethVandebrooke/439d8eda54d4b38614869f3bcf9f7f46 to your computer and use it in GitHub Desktop.
Basic Grunt Set Up
{
"presets": ["@babel/preset-env"]
}

Basic Grunt Set Up

file structure:

  • dist
    • built.js
    • built.min.js
  • temp
    • example.js
    • example2.js
  • src
    • example.js
    • example2.js

To install this, place the included files in your project and run the following command: npm install

The following command compiles javascript files from ES6 to ES5, concats the files defined in Gruntfile.js and minifies the final file. Run npm run build

module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
},
build: {
src: 'dist/built.js',
dest: 'dist/built.min.js'
}
}, concat: {
dist: {
src: ['temp/module1.js', 'temp/module2.js'],
dest: 'dist/built.js',
},
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
// Load the plugin that provides the "uglify" task.
grunt.loadNpmTasks('grunt-contrib-uglify');
// Default task(s).
grunt.registerTask('default', ['concat','uglify']);
};
{
"name": "basic-grunt",
"version": "1.0.0",
"description": "",
"main": "part1.js",
"scripts": {
"build": "babel src -d temp && grunt"
},
"author": "Seth Vandebrooke",
"license": "MIT",
"dependencies": {},
"devDependencies": {
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/preset-env": "^7.3.1",
"grunt": "^1.0.3",
"grunt-contrib-concat": "^1.0.1",
"grunt-contrib-uglify": "^4.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment