新建文件夹,按住shift右击选择在此处打开命令窗口。

npm init

npm install webpack --save-dev

新建hello.js文件,function hello(str){ alert(str); }

webpack hello.js hello.bundle.js

新建world.js文件 function world(){ return { } }

改hello.js为 require("./world.js");

运行

新建style.css body{background:#ccc;}

改hello.js为require("style-loader!css-loader!./style.css");

npm install css-loader style-loader --save-dev

新建index.js文件<script src="hello.bundle.js"></script> hello.js文件加上hello('hello world!');