webpack_ (Chapter I) _ The correct installation

Webpack built environment

webpack is developed based on node module packaging tools, essentially by the node to achieve, you must first install the node environment.
Nodejs will to a large extent the new version of the package to improve the speed of webpack.
Improve webpack Packing speed: First, to maintain nodejs new version as much as possible, and the other is to keep as much as possible of the new version webpack. High version webpack will use some of the features of the new version of the node, to improve packaging speed.
After installing the node
to create a new folder, run npm init: We have previously installed the npm package management tool that can help us create a project in the form of node specification, or create a node of the package file, in order to use webpack management project, to let your project compliant node, and run npm initto the initial project, the project will comply with the specifications node, enter: project name -> project versions -> item description ... all the way round to select yes created the project. In fact npn init is to generate a package.json in the project file, which describes some of the information node or item node package, the name of the project (package), version, description ...
(direct npm init -y execution would not have asked us how to configure, and directly help us generate the default configuration items)
Here Insert Picture Description
where we can add some things to the content, such as a plus "private": true: this means that the project is a private project, it will not be released to the warehouse in npm line. Then we can put the main configuration items correspond to remove, because the project will not be referenced outside, but their use is not necessary to expose a JS file out, scripts label stuff inside can be removed, license if you want to open, can be written as MIT , so you package.json configured.
After installation webpack project initialization
installed webpack in two ways:
1. Global Installation: executionnpm install webpack webpack-cli -g
Run webpack -v can view the version installed webpack, while explanation has been webpack global installed a
global installed webpack not recommended: Add two items are packaged with webpack, if the global installed webpack, webpack version number is fixed, but the fact is the use of a webpack3 configuration, and the other is through webpack4 configured so webpa3 project is not up and running, if installed by a global, two different versions of project success is not possible to run at the same time.
npm uninstall webpack webpack-cli -gUninstall globally installed webpack
2. project installation within webpack: into the project, execution npm install webpack webpack-cli --save-devis equivalent to npm install webpack webpack-cli -D
when installed webpack, the project will be more of node_modules, there is webpack and its dependent packages.
Then run webpack -v found can not find, because when webpack enter this command, nodejs will try to find the global module directory webpack, but this time we are not installed in the global webpack, but installed in the project inside, so we could not find webpack this command, but node provides a npx command, let's run through webpack npx. Execution npx webpack -vexecution can be printed in this publication. npx command will help us find webpack in node_modules files in the current project.

Install the specified version of the package: the package name + @ + version
eg: npm install [email protected] -D
how to view the package of those versions in existence? npm info + package name
eg: npm info webpackyou can view the version history of webpack
npm install [email protected] webpack-cli -D
deleted rely node_modules, npm install will help us to project the dependent packages are installed
so far webpack is now installed

Published 137 original articles · won praise 30 · views 260 000 +

Guess you like

Origin blog.csdn.net/hani_wen/article/details/93027633