官术网_书友最值得收藏!

  • Bootstrap 4 Cookbook
  • Ajdin Imsirovic
  • 494字
  • 2021-07-02 21:07:58

How to do it...

  1. Let's create new files:
      cd && cd workspace
touch Gruntfile.js package.json
  1. Open the package.json file:
      c9 package.json
An important thing to note is that if you had the old package.json file open before, during, and after the file renaming using the mv command, using the c9 <filename> command might point to the tab that was not closed, and show the old version of the file. Feel free to close this file's tab by middle-clicking on it (this works just like browser tabs, at least on c9.io running in Chrome).
  1. The package file is completely empty, so let's add some code to it:
      {
"name": "customGrunt",
"version": "",
"devDependencies": {
"grunt": "~1.0.1"
}
}

What are we doing in the package.json file? We are giving our package just some key:value pairs. Specifically, we are giving it a name, a version, and devDependencies. Right now, only the devDependency grunt is listed.

  1. Now we will add another plugin, grunt-contrib-copy, by typing the following command in our Bash console:
      npm install grunt-contrib-copy --save-dev

Now, we can see that the grunt-contrib-copy plugin has been added to the list of devDependencies in our custom package.json:

      {
"name": "customGrunt",
"version": "",
"devDependencies": {
"grunt": "~1.0.1",
"grunt-contrib-copy": "^1.0.0"
}
}

More information about this plugin can be found at https://www.npmjs.com/package/grunt-contrib-copy. In a nutshell, this plugin copies files as we specify.

  1. Now that we have prepared our package.json file, we can tell Grunt how to use it, by coding Gruntfile.js. We will begin by opening the currently empty Gruntfile.js:
      c9 Gruntfile.js
  1. We will add the following code to our Gruntfile.js:
      'use strict';
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

// Define the copy task
copy: {
main: {
expand: true,
src: 'dist/css/bootstrap.css',
dest: 'copy',
},
},
});

grunt.loadNpmTasks("grunt-contrib-copy");
grunt.registerTask("default", ['copy']);
};
If you need a detailed explanation of how the above Gruntfile.js code works, take a look at the How it works… section.
  1. Finally, it is time to run our default Grunt task, with verbose logging:
      grunt -v

Running the preceding command will create a new folder and will copy the bootstrap.css file in the workspace/copy/dist/css/bootstrap.css

path.

  1. Now that we have a basic understanding of just how Grunt runs its tasks, as well as how to modify its tasks to our liking, let's undo the changes we did. However, we will still keep our experimental files, just to have them handy if needed. What follows are the commands used to achieve this. The following commands will get to the root, navigate to /workspace, and make a new folder called GruntExperiment:
      cd; cd workspace; mkdir GruntExperiment
  1. Now, let's move our custom Gruntfile.js and package.json files, with the following two commands:
  1. Finally, we need to rename our original files to their original names, running the following commands (note that there are two commands here, for two files; each command was split on two rows so they can fit this page width):
      mv node_modules/bootstrap/Gruntfile.jsORIGINAL 
node_modules/bootstrap/Gruntfile.js;
      mv node_modules/bootstrap/package.jsonORIGINAL 
node_modules/bootstrap/package.json
主站蜘蛛池模板: 盐源县| 集贤县| 开封县| 广丰县| 龙里县| 东丽区| 垣曲县| 青铜峡市| 黄山市| 黄石市| 永川市| 伊吾县| 永兴县| 铜梁县| 昆山市| 土默特左旗| 丹阳市| 手机| 儋州市| 杭州市| 依兰县| 温州市| 平凉市| 东阿县| 乃东县| 新余市| 于田县| 慈溪市| 资兴市| 赤城县| 万载县| 鸡泽县| 湖北省| 麻江县| 二手房| 社旗县| 宝坻区| 黑山县| 武城县| 道孚县| 伊宁县|