Webstorm+webpack Creating a Project

Source: Internet
Author: User

http://blog.csdn.net/mafan121/article/details/71211922

1. Create an empty project using Webstrom

2. Create folders and files under the project

A. Create a CSS folder to hold the Index.css file with the following file contents:

[CSS]View PlainCopyprint?
  1. p{
  2. font-size: 24px;
  3. padding:0 100px;
  4. color:blue;
  5. }
  6. P:nth-of-type (2) {
  7. font-size: 30px;
  8. text-align: Center;
  9. color:black;
  10. font-family:"the Young Circle";
  11. }
  12. P:nth-of-type (3) {
  13. color: red;
  14. font-weight:bold;
  15. text-align: Right ;
  16. }


B. Create the index folder and store the index.html file with the following file contents:

[JavaScript]View PlainCopyprint?
    1. <! DOCTYPE html>
    2. "en" >
    3. <meta charset="UTF-8" >
    4. <title>myFirstDemo</title>
    5. <body>
    6. <div id="app" ></div>
    7. <script src="Bundle.js" ></script>
    8. </body>


C. Create the Data folder to hold the Index.json file with the following file contents:

[JavaScript]View PlainCopyprint?
    1. {
    2. " name":"Hello Webpack",
    3. "Content":"This is my first demo",
    4. "Start":"Ready go!"
    5. }


D. Create Jsproject folder to hold Createdom.js and entry.js files.

Entry.js

[JavaScript]View PlainCopyprint?
    1. Require ('./...  /css/index.css ');
    2. var createdom = require ('./createdom.js ');
    3. document.getElementById (' app '). AppendChild (CreateDOM ());

Createdom.js

[JavaScript]View PlainCopyprint?
    1. var message=require ('./...  /data/index.json ');
    2. Module.exports = function () {
    3. var greet=document.createelement (' div ');
    4. Greet.innerhtml="<p>" +message.name+"</p>" +"<p>" +message.content+"</p>"  +"<p>" +message.start+"</p>";
    5. return greet;
    6. };




3. Command operation

Execute the following command in the Webstorm terminal window:

A. Generating a dependent file Package.json (default is generated at the root directory)
CNPM Init

B. Install dependencies in turn (the Node_modules folder appears under the installation project root, which contains download dependencies)

(1) cnpm Intsall webpack-g

(2) cnpm install--save-dev Webpack

(3) cnpm install--save-dev Css-loader

(4) cnpm install--save-dev Style-loader

(5) cnpm install--save-dev Json-loader

(6) cnpm install--save-dev Webpack-dev-server

4. Configuring the Webpack.config.js File

Create a webpack.config.js file under the project root path with the following file contents:

[JavaScript]View PlainCopy print?
  1. var webpack = require (' webpack ');
  2. Module.exports = {
  3. //2, Import and export document configuration
  4. entry:__dirname+'/jsproject/entry.js ',//The specified portal file, "__dirname" is a global variable in node. js that points to the directory where the current execution script resides
  5. Output: {//outputs
  6. Path: __dirname+'/index ',//output path
  7. FileName: ' bundle.js '//output file name
  8. },
  9. Module: {//Add loader description in config file to indicate what loader processing is required for each type of file
  10. Loaders: [
  11. {//json loader
  12. Test:/\.json$/,
  13. Loader: "Json-loader"//note-loader can not be omitted, online said to be omitted, the test compiled will error
  14. },
  15. {//5, compiling ES6 configuration
  16. test:/\.js$/,
  17. Exclude:/node_modules/,
  18. Loader:' babel-loader ',//In the Webpack module section of the loaders configuration can be
  19. query:{
  20. presets:[' es2015 ',' react ']
  21. }
  22. },
  23. {//3, Css-loader
  24. test:/\.css$/,
  25. Loader:' style-loader!css-loader '//Add a handle to the style sheet
  26. }
  27. ]
  28. },
  29. ///4, Server dependent package configuration
  30. Devserver: {//NOTE: There are many colors properties on the Web, but the actual webpack2.x already does not support this property.
  31. Contentbase: "./index",//directory where the local server loads the page
  32. Historyapifallback: True,//Do not jump
  33. Inline: true//real-time refresh
  34. //hot:true,//do not write this property, or the browser cannot update automatically
  35. //publicpath: "/asses/",//After setting the property, Webpack-dev-server will be relative to the path
  36. },
  37. Plugins:[]//Plugins
  38. }


The file directory at this time is:

5. Start the service

In the terminal, enter:

Webpack

When execution is complete, enter:

Webpack-dev-server

Then enter it in the browser: http://localhost:8080/

You can see the effect at this point and update the code. The browser is also refreshed in real time.

Webstorm+webpack Creating a Project

Related Article

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.