一 webpack 初识

2019-05-16  本文已影响0人  i0S_毛_宇

DEMO

初始化

  mkdir webpack-test
  cd webpack-test
  npm init
  npm install webpack  --save-dev

创建 hello.js hello.css

hello.js

// require('style-loader!css-loader!./hello.css')
require('./hello.css')

function hello(str) {
    alert(str);
}

hello('hello world')
hello.css

html, body {
    background-color: red;
}

执行webpack生成命令

 // webpack hello.js -o ./dist/hello_bundle.js --watch
 webpack hello.js -o ./dist/hello_bundle.js --module-bind 'css=style-loader!css-loader' --watch

看效果,创建一个index.html

<!DOCTYPE html>
<html>
<head>
    <title>webpack-test</title>
</head>
<body>
    <script type="text/javascript" src="./dist/hello_bundle.js"></script>
</body>
</html>
上一篇下一篇

猜你喜欢

热点阅读