webpack用法1

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

  2. npm init

  3. npm install webpack --save-dev

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

  5. webpack hello.js hello.bundle.js 

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

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

  8. 运行

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

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

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

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