Webpack tutorial (1)-first experience, first experience
First, install webpack globally, then initialize a project in npm, and install the webpack development tool locally.
$ Npm install webpack-g
Npm init (project name)$ Npm install
One: Style Create a index.css file under SRC.Write the following code:body{background-color:red;}Introduce this CSS file in App.jsImport "./index.css";Now we execute NPM run start directly. See what happens.There was this mistake. Because Webpack itself is not aware of CSS code, so we need to configure to let it recognize the CSS codeCss-loader---> Parsing cssInstallation: npm i-d css-loaderWe also need to configure the configuration file in
commonjs2 method, will error---Prompt in the packaging after the App.js moduleis not defined;Note: Thedependencies of AMD and CMD are determined by the parameters of the define, i.e. define(‘B‘, [‘A‘], () => {}) the name of the current module is B, and depends on the a module. But in fact amd and CMD, the first parameter is not set, because there is a problem, COMMONJS usage specification is dependent on a module to require come in, exposing this module for other modules to use exports. 4, our
First of all, 2 kinds of router are introduced into the configuration of the Index.jsImport vue from ' Vue 'Import Router from ' Vue-router 'Import login from ' @/components/login 'Vue.use (Router)1. The first form of notationExport default New Router ({Routes: [{Path: '/login ',Component:login}]})2. The second type of notationvar router = new Router ();Router.map ({'/login ': {Path: '/login ',Component:log
First install webpack globally, then NPM Initializes a project and installs the Webpack development tool locally$ NPM Install Webpack-gNPM Init (project name)$ NPM Install Webpack-dev-server--save-devCreate the App folder under the project directory and create the Index.js file, writing the following codeConsole.log ('
crazy error.Originally VUE-CLI to initialize the project will help us install eslint This code writing specification Checker,You multiple spaces, less space will be GG, the most is a tab prompt error, I up to 249 errors, the days of killing do not know what I did ....Close Eslint Pit Daddy configuration, find the Build folder under the Webpack.base.conf.js comment out (do not put this code all comments, will error, only comments inside the configuration code is OK.) )OK, compile pass, go to loc
126. Use the same template file to generate different files and different titles, modify the Webpack.config.js file, the code is as followsvar htmlwebpackplugin = require ("Html-webpack-plugin"); module.exports = {entry:{main: './src/script/main.js ', A: './ Src/script/a.js '},output:{path: './dist ', filename: ' js/[name]-[hash].js ',},plugins:[new htmlwebpackplugin ({ Template: ' index.html ', filename: ' a.html ', Inject:false,title: ' This is a.ht
of files through file extensions (or regular expressions).
Loader can be npm published and installed.
In addition to package.json the main designations passed, the usual modules can also be exported with a loader to use.
Loader can access the configuration.
Plugins allow loader to have more features.
Loader can issue additional arbitrary files.
The 1.2 Loader itself is also a JavaScript module running in the node. JS environment, which typically returns a function.Loade
119. Output the contents of the Htmlwebpackplugin.options, modify the template file index.html, the code is as follows120. RePack with the CNPM run Webpack command650) this.width=650; "Src=" https://s5.51cto.com/wyfs02/M00/8D/C7/wKioL1iqrrDDwjzYAABFVd-z-kU974.png-wh_500x0-wm_ 3-wmp_4-s_2074528850.png "title=" 120.png "alt=" Wkiol1iqrrddwjzyaabfvd-z-ku974.png-wh_50 "/>121. View the contents of the generated index-d331f7ab6afb27b67263.html file output65
introduction of these two files in Index.jsModify the Component.js file so that it adds an incoming class name to the elementAdd the following configuration in Webpack.config.jsWe execute the NPM run Start command if you seeThe package is successful.Open Browser http://localhost:8080/You can see that the same class names are displayed properly, looking at the document structure on the right, and discovering that our class name is not Class1.The original CSS modules the name of our class hash, w
introduction of these two files in Index.jsModify the Component.js file so that it adds an incoming class name to the elementAdd the following configuration in Webpack.config.jsWe execute the NPM run Start command if you seeThe package is successful.Open Browser http://localhost:8080/You can see that the same class names are displayed properly, looking at the document structure on the right, and discovering that our class name is not Class1.The original CSS modules the name of our class hash, w
Let's run the Webpack command first.See App.js only 4k.Install reactNPM Install react--sava-devIntroducing react in the App/index.js fileRun WebpackSee that our App.js file has reached 100k.Because the app.js contains a large amount of code for react, it causes the volume to increase.If a user's internet speed is only 1k/s, and App.js has the process of loading CSS, such as the CSS file has not been separated out of the situation, the user will wait s
113. Modify the template file by using the For loop to output the contents of Htmlwebpackplugin index.html114. RePack with the CNPM run Webpack command650) this.width=650; "Src=" https://s2.51cto.com/wyfs02/M00/8D/C9/wKiom1iqq_2CU--mAABGZs9fdo0309.png-wh_500x0-wm_ 3-wmp_4-s_1438976236.png "title=" 114.png "alt=" Wkiom1iqq_2cu--maabgzs9fdo0309.png-wh_50 "/>115. View the contents of the index-0707837fd67a7b4a8e3e.html file output650) this.width=650; "Sr
116. Output the contents of the Htmlwebpackplugin.files, modify the template file index.html, the code is as follows117. RePack with the CNPM run Webpack command650) this.width=650; "Src=" https://s4.51cto.com/wyfs02/M01/8D/C9/wKiom1iqrXWiacBnAABGpwp_hQM417.png-wh_500x0-wm_ 3-wmp_4-s_884700443.png "title=" 117.png "alt=" Wkiom1iqrxwiacbnaabgpwp_hqm417.png-wh_50 "/>118. View the contents of the generated index-9b7e6d15108bc45c5cbd.html file output650)
First-installed dependenciesFile-loader--save-devNPM Install Image-webpack-loader --save-devNPM Install Url-loader--save-devAdd the following configuration to the Webpack.config.js fileThe image is introduced as a background image in a CSS file.Run NPM run startOpen Browser http://localhost:8080/See that the picture has been introduced and the name has been hashed.See what Url-loader is like, and also modify the Webpack.config.js fileMeaning is less
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.