Webpack3簡單入門1

使用 yarn 測試 webpack 的使用教程。javascript

本工程代碼css

建立工程

$ mkdir test-webpack-app-yarn
$ cd test-webpack-app-yarn
$ yarn init
# ...

安裝 webpack

$ yarn add webpack

# 新建一個 webpack 配置文件
$ touch webpack.config.js

# 內容:
module.exports = {
  entry: [
    './index.js'
  ],
  output: {
    path: __dirname,
    filename: 'bundle.js'
  }
}

添加工程內容

# index.js
$ touch index.js

# 內容:
document.write("Hello world, Webpack!")
# index.html
$ touch index.html

# 內容:
<html>
  <head>
    <meta charset="utf-8">
    <title>Hello, Webpack</title>
  </head>
  <body>
    <div id="app" />
    <script src="bundle.js" type="text/javascript"></script>
  </body>
</html>

編譯運行

$ yarn run webpack
$ open index.html -a Google\ Chrome

說明

若是過程當中發生錯誤,yarn會在工程根目錄下自動生成yarn-error.log文件。html

關於 yarnjava

相關文章
相關標籤/搜索