Webpack2的基本使用
生活随笔
收集整理的這篇文章主要介紹了
Webpack2的基本使用
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
安裝Webpack2
npm install -g webpack
也可以通過yarn來安裝
創建文件index.js
import _ from 'lodash';function component () {var element = document.createElement('div');/* lodash is required for the next line to work */ element.innerHTML = _.join(['Hello','webpack'], ' ');return element; }document.body.appendChild(component());創建文件index.html
<!DOCTYPE html> <html> <head><title>webpack 2 demo</title> </head> <body> <script src="dist/bundle.js"></script> </body> </html>通過npm init創建package.json文件
安裝lodash
npm install --save lodash
創建webpack的配置文件webpack.config.js
var path = require('path');module.exports = {entry: './app/index.js',output: {filename: 'bundle.js',path: path.resolve(__dirname, 'dist')} };最終目錄結構
運行webpack
下次介紹loader和plugin的使用。
參考資料
webpack1
http://webpack.github.io/docs/tutorials/getting-started/
webpack2
https://webpack.js.org/
總結
以上是生活随笔為你收集整理的Webpack2的基本使用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android Studio的Gradl
- 下一篇: 中国的支付清算体系