欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

詳解搭建es6+devServer簡單開發(fā)環(huán)境

 更新時(shí)間:2018年09月25日 11:21:55   作者:axin  
這篇文章主要介紹了詳解搭建es6+devServer簡單開發(fā)環(huán)境,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

搭建基于es6和熱加載的前端簡單開發(fā)環(huán)境,適合demo類小項(xiàng)目,這樣就不用依賴browsersync等多余的東西

目錄結(jié)構(gòu)

  1. /src
    1. index.js
    2. index.html
  2. /dist

安裝依賴

注意版本,尤其是babel,可去babel的npm地址查看,那里不會錯

#bebal相關(guān)
yarn add babel-core babel-loader babel-preset-env

# webpack相關(guān)
yarn add webpack webpack-cli webpack-dev-server html-webpack-plugin

package.json

{
 "name": "design-pattern",
 "version": "1.0.0",
 "description": "js設(shè)計(jì)模式的學(xué)習(xí)深入",
 "main": "index.js",
 "author": "axin <laputacloud@163.com>",
 "license": "MIT",
 "scripts": {
  "dev": "webpack-dev-server --config ./webpack.dev.config.js --mode development"
 },
 "dependencies": {},
 "devDependencies": {
  "babel-core": "^6.26.3",
  "babel-loader": "7",
  "babel-preset-env": "^1.7.0",
  "html-webpack-plugin": "^3.2.0",
  "webpack": "^4.19.1",
  "webpack-cli": "^3.1.0",
  "webpack-dev-server": "^3.1.8"
 }
}

webpack.dev.config.js

const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
 entry: './src/index.js',
 output: {
  path: __dirname,
  filename: './dist/bundle.js'
 },

 module: {
  rules: [{
   test: /\.js?$/,
   exclude: /(node_modules)/,
   loader: 'babel-loader'
  }]
 },

 plugins: [
  new htmlWebpackPlugin({
   template: './index.html'
  })
 ],

 devServer: {
  contentBase: path.join(__dirname, './dist'),
  open: true, // 自動打開瀏覽器
  port: 6688, // devServer對應(yīng)的端口號
 }
}

.babelrc 可根據(jù)需要配置

{
 "presets": ["env"]
}

然后就可以執(zhí)行npm run dev就可以開啟開發(fā)環(huán)境

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論