+1

Webpack - Getting Started

How to install webpack

$ npm install webpack -g

This makes the webpack command available.

SETUP THE COMPILATION

Start with a empty directory.

Create these files: entry.js

document.write("It works.");

index.html

<html>
    <head>
        <meta charset="utf-8">
    </head>
    <body>
        <script type="text/javascript" src="bundle.js" charset="utf-8"></script>
    </body>
</html>

Then run the following:

$ webpack ./entry.js bundle.js It will compile your file and create a bundle file.

If successful it displays something like this:

Version: webpack 1.13.3 Time: 24ms Asset Size Chunks Chunk Names bundle.js 1.42 kB 0 [emitted] main chunk {0} bundle.js (main) 28 bytes [rendered] [0] ./tutorials/getting-started/setup-compilation/entry.js 28 bytes {0} [built]

Open index.html in your browser. It should display It works.

SECOND FILE: content.js

module.exports = "It works from content.js.";

update entry.js

- document.write("It works.");
+ document.write(require("./content.js"));

And recompile with:

$ webpack ./entry.js bundle.js Update your browser window and you should see the text It works from content.js..

source: https://webpack.github.io/docs/tutorials/getting-started/


All rights reserved

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí