Webpack-----The first chapter

Source: Internet
Author: User

Don't say much nonsense, go straight to the actual combat!!!

1. Create a new folder on the desktop: webpack_test

2. Create a new folder under the Webpack_test folder demo01

3. Then create two JS files Main.js and Index.js files under the Demo01 folder

4. Write a function in Index.js and export

// declare a function and export it using export function Add (A, b) {    + b);}

5. In Main.js, import the function in Index.js and call

Import {Add} from './index.js 'Add (3, 5); Add (78, 100);

6. Create a file under the root directory webpack_test index.html

<!DOCTYPE HTML><HTML><Head>    <MetaCharSet= "Utf-8">    <title>I study Webpack</title></Head><Body></Body></HTML>

7. Then create a new Webpack.config.js file under the root directory Webpack_test and write the configuration rule

Const PATH = require (' path ') Const Htmlwebpackplugin= Require (' Html-webpack-plugin ') Config={entry: { main:'./demo01/main.js '}, Output: {path:path.resolve (__dirname,' Dist ')//Specify the path to the export file filename:‘[Name]. js '//This is the same as the background color of the Chunk name, you can also specify the exit path as stipulated './[name].js ' exit will be in JS this folder}, module: {rules: [{test:/\.js$/, exclude:/node_modules/, Loader:' Babel-loader '}]}, plugins: [Newhtmlwebpackplugin ({filename:' Index_webpack.html ', Template:' Index.html '})]}module.exports= Config

8. Install various packages at the terminal

                NPM init                                         ,         &N Bsp             Initialize
                CNPM Install we Bpack--save-dev                        Download Webpack module
                CNPM install babel-loader                                    This package allows the use of   babel and   Webpack&nbs p; Convert JavaScript files
                CNPM install babel-core      &N Bsp                                 to interpret JS files

Html-webpack-plugin Download the required plugins

9, then use Webpack compile, open the time to open the DIS directory index_webpack.html

Webpack-----The first chapter

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.