Webpack Configuring backups

Source: Internet
Author: User

Package.json:

{  "name": "Webpacktest",  "version": "1.0.0",  "description": "",  "main": "Index.js",  "scripts": {    "app": "Webpack-dev-server--inline--hot",    "dev": "Set Node_env=dev&&webpack",    "test": "Set Node_env=test&&webpack ",    " Pro ":" Set Node_env=pro&&webpack "  },  " keywords ": [],  "Author": "",  "license": "ISC",  "dependencies": {    "jquery": "^3.1.1",    "underscore": "^1.8.3"  },  "Devdependencies": {    "Css-loader": "^0.26.0", "    extract-text-webpack-plugin": "^1.0.1",    "File-loader": "^0.9.0",    "Html-webpack-plugin": "^2.24.1",    "Json-loader": "^0.5.4",    " Style-loader ":" ^0.13.1 ",    " Uglify-js ":" ^2.7.4 ",    " Url-loader ":" ^0.5.7 ",    " Webpack ":" ^1.13.3 ",    "Webpack-dev-server": "^1.16.2"  }}

Webpack.config.js:

/** * Created by Administrator on 2016/11/28 0028. *//*webpack for Spa (single page app) using */var webpack=require (' webpack '); var extracttextplugin=require (' Extract-text-webpack-plugin '); var extractcss=new extracttextplugin (' css/[name].css '); var htmlwebpackplugin = Require (' Html-webpack-plugin '); module.exports={entry: {app: __dirname + '/src/js/index.js ', */* reference nod in square brackets        E_modules corresponding module */lib:[' jquery ', ' underscore ']},/* entry file */output:{Path:__dirname + "/assets/",/* Output path */ FileName: ' js/index.js ',/* output filename */publicpath: ' http://192.168.1.108:7777/assets '/* cache area, Debug or go online using */},/*w Ebpack-dev-server Server Configuration */devserver:{contentbase: "./",/* root directory */host: "192.168.1.108",/* Native address */port: '            7777 ',/* Port settings */color:true/* Color Setting *//* Module settings */module:{/* settings file with what loader to read */loaders:[/*            {test:/\.css$/,*//* matches *//* loader: ' Style-loader!css-loader ' *//*! is a connector, file interpreter *//*        },*/    {test:/\.css$/, loader:extractCss.extract (' Style-loader ', ' Css-loader ')}, {test:/\.less$/, loader: ' Style!css!less '}, {test: /\.json$/, Loader: ' JSON '}, {test:/\. (                Gif|jpg|png) $/,/* Picture resources are compressed at the time of loading, when the picture is less than 7KB into the base64 format embedded in order to reduce the number of HTTP requests, when the picture is greater than 7kb, will be generated under/assets/images/compressed picture */ Loader: ' url-loader?limit=7000&name=/images/[hash:6]. [Name]. [ext] '}]},/* plugin */plugins:[new webpack.            Hotmodulereplacementplugin (),/* hot-swappable */extractcss, new Htmlwebpackplugin ({title: ' Leyi ', FileName: '. /home.html ', template:__dirname+ '/src/tpl/indextpl.html ', inject: ' Body '/* * to generate the template to the bottom of the body tag */})            ,/*JS compression */New Webpack.optimize.UglifyJsPlugin ({compress: {warnings:false     }   }),/* Insert a global variable into all the code */New Webpack. Provideplugin ({$: ' jquery '}),/* Extract some JS files separately into a single JS file, general extraction of public JS packaged into a shared JS file */New WEBPACK.O Ptimize. Commonschunkplugin ("Lib", "Js/lib.js")], resolve:{//Find modules from here to find, can be local somewhere, or remote network address to get module root: ' F :/webpacktest/',//Auto extension file suffix name, require module can not write suffix extensions:[', '. js ', '. json ', '. less ',//module alias definition, req        Uire the time to write an alias, you can not write a long address after the definition of alias:{happy: "Externalmodules/happy.js", Funy: "Src/js/funy.js" }},/* Automatic monitoring */watch:true};/* first configure the development, test, Production Environment Run command (note the space problem) in Package.json, according to the running command set the corresponding action */if (process.env.node_env=== ' Dev ') {console.info (' Executing a development environment ');} else if (process.env.node_env=== ' test ') {console.info (' Executing a test environment ');} else{Console.info (' Executing a production environment ');}

Demo:

Http://files.cnblogs.com/files/leyi/webpackTestDemo.rar

Webpack Configuring backups

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.