These days into the new company, the leadership let me learn the knowledge of Vue, just learn the use of Webpack.
Basic use
Create Vue project: Vue init webpack Program name add Dependency package: NPM/cnpm Install package name--save-Dev debug: npm run Dev Pack: NPM r UN build
Debug and Build commands to make configuration changes in Package.json
1, Package.json file Introduction
The reference information of the package that the program relies on and the commands for debugging and build are configured in the file.
Here are some of the main information:
Basic configuration information:
1 " Name ":" Xjtest ", // project name 2 " version ":" 1.0.0 ", // version 3 "description": "A vue.js project", // Introduction 4 "Author": ", // author
Command configuration information:
This configuration is the program debugging, packaging and other command information
1 "Scripts": {2 "dev": "Webpack-dev-server--inline--progress--config build/ Webpack.dev.conf.js ",3 " Start: "npm run Dev" ,4 "Build": "Node Build/build.js "5 }
These commands can be added or modified on their own, such as we need to develop both the PC station and Mobile station, we can define different running and packaging commands here, as follows:
1 "Scripts": {2 "dev-pc": "Node Compile/build/dev-server.js",3 "Dev-mobile": "Node Compile/build/dev-server.js-mobile",4 "Start": "Node build/ Dev-server.js ",5 " build-pc ":" Node Compile/build/build.js ",6 "Build-mobile": "Node Compile/build/build.js-mobile"7 }
2. Build File Introduction
Here is the place to store the necessary configuration information for debugging and packaging, as can be seen from the scripts configuration information above.
Build.js File Description:
1' Use strict '2Require ('./check-versions '))()3 //environment variable Settings4Process.env.NODE_ENV = ' production '5 6 //Introducing Dependencies7Const ORA = require (' ora ')8Const RM = require (' Rimraf ')9Const PATH = require (' path ')TenConst CHALK = require (' Chalk ') OneConst WEBPACK = require (' Webpack ') AConst CONFIG = require ('.. /config ')//project configuration file -Const WEBPACKCONFIG = require ('./webpack.prod.conf ')//webpack configuration Information - varUtils = require ('./utils ')//basic Operation Definition the -Const spinner = Ora (' Building for production ... ')) - Spinner.start () - +RM (Path.join (Config.build.assetsRoot, config.build.assetsSubDirectory), err = { - if(ERR)ThrowErr + //This is done by loading the Webpackconfig to package the project AWebpack (Webpackconfig, (err, stats) = { at spinner.stop () - .... - }) -})
webpack.base.conf Introduction:
1Entry: ' Main.js ',//Program Entry2 3 //Output Information4 output: {5Path:config.build.assetsRoot,//read the output path from the configuration6FileName: ' [name].js ',//the file name of the output7 //set up a publishing path based on environment changes8PublicPath:process.env.NODE_ENV = = = ' Production '9?Config.build.assetsPublicPathTen : Config.dev.assetsPublicPath One},
webpack.prod.conf Introduction:
// output settings, Ibid. output: { path:config.build.assetsRoot, filename:utils.assetsPath (' [name].js '), ChunkFilename:utils.assetsPath (' [id].js ') },
Webpack Study Notes