美文网首页
webpack-study

webpack-study

作者: asmuzi | 来源:发表于2018-12-05 15:25 被阅读0次
目录
src
dist
新建文件
index.html
main.js
console.log('ok');

npm init -y
package.json
{
  "name": "webpack-study",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "webpack-dev-server --open --port 3000 --hot"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "html-webpack-plugin": "^3.2.0",
    "webpack": "^4.27.0",
    "webpack-cli": "^3.1.2",
    "webpack-dev-server": "^3.1.10"
  }
}

cnpm i webpack-dev-server -D

webpack.config.js
const path = require('path')

const htmlWebPackPlugin = require('html-webpack-plugin')

module.exports = {
    mode: 'development',
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'bundle.js'
    },
    plugins: [
        new htmlWebPackPlugin({
            template: './src/index.html',
            filename: 'index.html'
        })
    ]
}

npm run dev启动

相关文章

网友评论

      本文标题:webpack-study

      本文链接:https://www.haomeiwen.com/subject/tlcwcqtx.html