From 721f114286f8e893bc5a4ece7aace18d529bf751 Mon Sep 17 00:00:00 2001 From: "jason.zhu" Date: Tue, 23 Mar 2021 00:28:46 +0000 Subject: [PATCH] Grunt JS Tutorial #4 - Adding a Plugin (concatenating files) 1. Installed concat plugin 2. Modified config to have plugin --- .gitignore | 5 ++-- Gruntfile.js | 24 ++++++++++------- package-lock.json | 67 +++++++++++++++++++++++++++++++++++++++++++++++ package.json | 3 ++- 4 files changed, 86 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 6812980..d3996ad 100644 --- a/.gitignore +++ b/.gitignore @@ -29,7 +29,8 @@ dist/ .LSOverride # Icon must end with two \r -Icon +Icon + # Thumbnails ._* @@ -219,4 +220,4 @@ $RECYCLE.BIN/ # End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,executable,grunt,macos,node,vscode # Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) - +build \ No newline at end of file diff --git a/Gruntfile.js b/Gruntfile.js index eaf669e..832a5c8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -4,20 +4,24 @@ module.exports = function(grunt){ grunt.initConfig({ // pass in options to plugin, references to file, etc. + concat: { + js: { + src: ['js/*.js'], + dest: 'build/scripts.js' + }, + css: { + src: ['css/*.css'], + dest: 'build/styles.js' + } + } }); // Load plugins - // grunt.loadNpmTasks('') + grunt.loadNpmTasks('grunt-contrib-concat') + require('load-grunt-tasks')(grunt); // Register tasks - grunt.registerTask('run', function(){ - // task is a function with name is 'run' - console.log('I am running'); - }); + grunt.registerTask('concat-js', ['concat:js']); + grunt.registerTask('concat-css', ['concat:css']); - grunt.registerTask('sleep', function(){ - console.log('I am sleep'); - }); - - grunt.registerTask('all', ['sleep', 'run']) } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 3bc1b94..2957498 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,12 @@ "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "dev": true }, + "ansi-regex": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz", + "integrity": "sha1-w7M6te42DYbg5ijwRorn7yfWVN8=", + "dev": true + }, "ansi-styles": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", @@ -357,6 +363,12 @@ "integrity": "sha1-8NZtA2cqglyxtzvbP+YjEMjlUrc=", "dev": true }, + "escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "dev": true + }, "esprima": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/esprima/-/esprima-4.0.1.tgz", @@ -722,6 +734,43 @@ "v8flags": "~3.1.1" } }, + "grunt-contrib-concat": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/grunt-contrib-concat/-/grunt-contrib-concat-1.0.1.tgz", + "integrity": "sha1-YVCYYwhOhx1+ht5IwBUlntl3Rb0=", + "dev": true, + "requires": { + "chalk": "^1.0.0", + "source-map": "^0.5.3" + }, + "dependencies": { + "ansi-styles": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz", + "integrity": "sha1-tDLdM1i2NM914eRmQ2gkBTPB3b4=", + "dev": true + }, + "chalk": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz", + "integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=", + "dev": true, + "requires": { + "ansi-styles": "^2.2.1", + "escape-string-regexp": "^1.0.2", + "has-ansi": "^2.0.0", + "strip-ansi": "^3.0.0", + "supports-color": "^2.0.0" + } + }, + "supports-color": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz", + "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", + "dev": true + } + } + }, "grunt-known-options": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/grunt-known-options/-/grunt-known-options-1.1.1.tgz", @@ -774,6 +823,15 @@ "function-bind": "^1.1.1" } }, + "has-ansi": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz", + "integrity": "sha1-NPUEnOHs3ysGSa8+8k5F7TVBbZE=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", @@ -1630,6 +1688,15 @@ } } }, + "strip-ansi": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz", + "integrity": "sha1-ajhfuIU9lS1f8F0Oiq+UJ43GPc8=", + "dev": true, + "requires": { + "ansi-regex": "^2.0.0" + } + }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", diff --git a/package.json b/package.json index 6254da1..98f37d7 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,8 @@ "main": "app.js", "dependencies": {}, "devDependencies": { - "grunt": "^1.3.0" + "grunt": "^1.3.0", + "grunt-contrib-concat": "^1.0.1" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1"