webapck.config.js

const path = require('path')
const webpack = require('webpack')
// const UglifyPlugin = require('uglifyjs-webpack-plugin')
const VueloaderPlugin = require('vue-loader/lib/plugin')


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

module.exports = {
  entry: './src/index.js',

  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: '[name][hash].js',
    clean: true
  },

  module: {
    rules: [
      {
        test: /\.js|jsx/,
        include: [
          path.resolve(__dirname, 'src')
        ],
        use: 'babel-loader',
      },
      { test: /\.css$/, use: ['style-loader', 'css-loader'] },
      { test: /\.vue$/, use: 'vue-loader' }
    ],
  },

  // 代码模块路径解析的配置
  resolve: {
    modules: [
      "node_modules",
      path.resolve(__dirname, 'src')
    ],

    // extensions: [".wasm", ".mjs", ".js", ".json", ".jsx"],
  },

  plugins: [
    // new UglifyPlugin(),
    new HtmlWebpackPlugin({
      template: 'index.html',
      filename: 'index.html',
      // inject: "body",
    }),
    // 使用 uglifyjs-webpack-plugin 来压缩 JS 代码
    // 如果你留意了我们一开始直接使用 webpack 构建的结果,你会发现默认已经使用了 JS 代码压缩的插件
    // 这其实也是我们命令中的 --mode production 的效果,后续的小节会介绍 webpack 的 mode 参数
    new webpack.HotModuleReplacementPlugin(),
    new VueloaderPlugin(),
    // new webpack.DefinePlugin({ // webpack自带该插件,无需单独安装
    //5.0不需要这个了
    //   'process.env': {
    //     NODE_ENV: process.env.NODE_ENV // 将属性转化为全局变量,让代码中可以正常访问
    //   }
    // })

  ],
  devServer: {

    host: 'localhost',
    // contentBase: path.resolve(__dirname, 'src'),
    // static: {
    //   directory: resolve(__dirname, 'dist')
    // },
    historyApiFallback: true,
    compress: true,
    port: 3000,  //端口好
    hot: true, // 开启热更新
    open: true, //是否打开浏览器
  },
  mode: 'development',

}

package.json

{
  "name": "five",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "b": "webpack",
    "start": "webpack-dev-server  --mode development",
    "watch": "webpack --watch"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.18.2",
    "@vue/compiler-sfc": "^3.2.37",
    "babel-loader": "^8.2.5",
    "html-webpack-plugin": "^5.5.0",
    "uglifyjs-webpack-plugin": "^2.2.0",
    "vue-loader": "^15.9.8",
    "webpack": "^5.72.1",
    "webpack-cli": "^4.9.2",
    "webpack-dev-server": "^4.9.0"
  },
  "dependencies": {
    "css-loader": "^6.7.1",
    "style-loader": "^3.3.1",
    "url-loader": "^4.1.1",
    "vue": "2.5.10",
    "vue-template-compiler": "2.5.10"
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值