webpack

作者: Daeeman | 来源:发表于2020-07-14 22:57 被阅读0次

    1、安装

    cd mypack --------//进入项目目录
    npm init ------------//初始化项目
    npm i webpack -D ------//安装webpack
    npm i webpack-cli -D --------//安装脚手架

    2、配置webpack.config.js

    //webpack是node写出来的  node写法  path  node内置语法
    let path = require('path');
    module.exports = {
      devServer:{
        port:3000,
        progress:true,
        contentBase:'./build',
        compress:true,
    }
      mode:'development', //模式  默认两种 production(生产)  development(开发-非压缩)
      entry:'./src/index.js',  //入口
      output:{
        filename:'bundle.js',   //打包后的文件名
        path:path.resolve(__dirname,'build'),  //路径必须是一个绝对路径 __dirname是指当前目录,不写也可以
      }
    }
    

    package.json

    {
      "name": "mypack",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "dev":"webpack-dev-server"
      },
      "author": "",
      "license": "ISC",
      "devDependencies": {
        "webpack": "^4.43.0",
        "webpack-cli": "^3.3.12"
      }
    }
    
    
    yarn add webpack-dev-server -D
    npx webpack-dev-server
    

    相关文章

      网友评论

          本文标题:webpack

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