使用 yarn 測試 webpack 的使用教程。javascript
本工程代碼css
$ mkdir test-webpack-app-yarn $ cd test-webpack-app-yarn $ yarn init # ...
$ 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