Simple to understand and npm webpack

Verbatim large column  https://www.dazhuanlan.com/2019/08/26/5d6335d738d56/


How to install a global node application?

npm install -g

package.json What is the role?

When publishing packages, you need npm npm initgenerate package.json document
information in package.json to describe the package and provide the required packages depend

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{ 
"Name": When "gulp-use", // release npm package needs, expressed npm package name
"version": "1.0.0", the version number // package
"description": "", / / for a simple description of this package
"main": "index.js", // entry document
"scripts": {
"Test": "echo" Error: NO specified Test "Exit. 1 &&" //
},
"Keywords" : [], // keyword
"author": "", // author
"License": "ISC", //
"devDependencies": {
"GULP": "^ 3.9.1", // depends other package version } }



npm install -save app and npm install -save-dev app What is the difference?

  • npm install --save app: To save the information to be loaded to rely package.json inside the module is used, the dependence is called

  • npm install --save-dev app: When the reliance on the use of development and testing, when the need to test, you can call the dependency

Node_modules search path is like?

Find nodule_modules => if (no) upwardly under a same directory to find the module => IF (no) then an upwardly ... => until it finds the root directory

What webpack that? And other similar tools than what are the advantages?

There are already existing modules and packaging management tool is not suitable for large-scale projects, especially single-page Web applications process. The most pressing reason is how a massive code base, the maintenance division and storage of various modules of resources to maintain dependencies between them, and seamlessly integrate them together to generate a request for the browser to load static resources.

These existing modular tools are not well completed the following objectives:

  • The dependency tree split into blocks loaded on demand

  • Load initialization time-consuming as little as possible

  • All kinds of static resources can be regarded as a module

  • The third-party libraries integrated into the module capacity

  • The ability to customize the logic package

  • Suitable for large projects, whether it is a single-page or multi-page Web applications

    And other similar tools than what are the advantages?

webpack advantages:

  • 1. Split Code

There are two modules Webpack tissue-dependent manner, synchronous and asynchronous. Asynchronous dependence as a division point, forming a new block. After optimizing the dependency tree, each asynchronous blocks are packaged as a single document.

  • 2.Loader

Webpack itself only native JavaScript processing module, but the converter may convert the loader types of resources into JavaScript module. Thus, any resource can be a module Webpack can handle.

  • 3. Smart parsing

Webpack have an intelligent parser can handle almost any third-party libraries, regardless of their form module is CommonJS, AMD or an ordinary JS document. Even when the load-dependent, allowing the use of dynamic expressions require ( "./ templates /" + name + ".jade").

  • 4. The plug-in system

Webpack there is a feature-rich plug-in system. Most of what functions are based on the plug-in system operation, but also the development and use of open source plug-ins Webpack to meet a variety of needs.

  • 5. Run Fast

Webpack use asynchronous I / O and multi-level cache to improve operational efficiency, which makes it possible to Webpack incredible speed fast incremental compilation.

What npm scripts that? how to use?

npm allowed inside package.json documents, field definitions using scripts script commands.

1
2
3
4
5
"scripts": {
"start": "node ./bin/www",
"webpack": "webpack --config ./src/webpack.config.js",
"watch": "onchange "src/**/*.js" "src/**/*.less" -- npm run webpack"
}

Input
npm run webpack
or
npm run watch
you can execute the corresponding script
, but such bulid start or the like, can be directlynpm start

Guess you like

Origin www.cnblogs.com/petewell/p/11411009.html