webpack knowledge to build the component library

1 .  inquirer.js - a user interacts with a command-line tool

2。 existsSync

Method Description:
  a synchronous detection method directory exists.
  If the directory exists returns true, if the directory does not exist return false
Syntax:
fs.existsSync (Pach);
Since the method belongs module fs, fs module incorporated before use var fs = require ( 'fs' );
receive parameters:
  path: the directory path detection
example:

var fs = require("fs");
var checkDir = fs.existsSync("checkDir");
console.log(checkDir);

3.

In fs module may check whether there is a file or directory exists method used.

1. Grammar

fs.exists(path, callback)

var isexist = fs.existsSync (path) // when a file or directory exists, the value is true, when a file or directory does not exist, the value of the parameter is false

2. Parameters

path: the full path and filename or directory name needs to be checked is specified file or directory;

callback: callback function for performing the specified file or directory information checking operation is completed, the callback function syntax is as follows:

function(exists){ …… }

parameter:

exists: when a file or directory exists, the value is true, when a file or directory does not exist, the value of the parameter is false.

var FS = the require ( 'FS' ); 
fs.exists ( './test.js', function (EXISTS) {
     IF (EXISTS) { 
        the console.log ( "the file exists!" ); 
    } 
    the else { 
        the console.log ( "the file does not exist!" ); 
    } 
});

 4 path.join the difference with path.resolve

1. For to / path segments starting, path.join simply splicing the path segments, and will path.resolve / start root fragment as a path, the path will be discarded before, like is the same as using the cd command in the terminal.

path.join('/a', '/b') // 'a/b'
path.resolve('/a', '/b') // '/b'

2. path.resolve always return an absolute path relative to the current working directory (working directory) is.

path.join('./a', './b') // 'a/b'
path.resolve('./a', './b') // '/Users/username/Projects/webpack-demo/a/b'

 

Guess you like

Origin www.cnblogs.com/xiaozhumaopao/p/11112772.html