当前位置: 首页 > news >正文

webpack环境配置分类结合vue使用

文件目录结构

 

按照目录结构创建好文件

控制台执行: npm install

/config/webpack.common.jsconst path = require('path')
const {merge} = require('webpack-merge')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const { VueLoaderPlugin } = require('vue-loader');
const HtmlWebpcakPlugin = require("html-webpack-plugin")
module.exports = {entry:'./src/main.js',output:{path:path.resolve(__dirname,'../dist'),filename:'[name].bundle.js'},plugins:[new CleanWebpackPlugin(),new HtmlWebpcakPlugin({template: path.resolve(__dirname,'../src/index.html')}),new VueLoaderPlugin()],module:{rules:[{test: /\.vue$/,loader: 'vue-loader'},{test: /\.css$/,use: ['vue-style-loader', 'css-loader','style-loader']}]},resolve: {extensions: ['.js', '.vue'],alias: {'vue$': 'vue/dist/vue.esm.js'}}
}

开发环境

 ./config/webpack.dev.js
/** @description: * @param: * @return: * @Date: 2024-03-06 14:07:54*/
const path = require('path')
const {merge} = require('webpack-merge')
const common = require('./webpack.common.js')module.exports = merge(common,{mode:'development',devtool:'inline-source-map',devServer:{static:path.join(__dirname,'../dist'),host:'localhost',port:8080,open:true}
})

生产环境

./config/webpack.prod.js
/** @description: * @param: * @return: * @Date: 2024-03-06 14:08:25*/
const path = require('path')
const {merge} = require('webpack-merge')
const common = require('./webpack.common.js')
const TerserWebpackPlugin = require('terser-webpack-plugin')
module.exports = merge(common,{mode:"production",output:{filename:'[name].[hash:7].js' //例如 wang.4678946.js},optimization:{minimize:true,minimizer:[new TerserWebpackPlugin()]}
})
src/main.js/** @description: * @param: * @return: * @Date: 2024-04-07 17:50:43*/
import Vue, { h } from 'vue'
import App from './App.vue'
new Vue({render:h=>h(App)
}).$mount('#app')
src/index.html<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Document</title>
</head>
<body><div id="app"></div><script src="../dist/build.js"></script>
</body>
</html>

src/App.vue<!--* @description: * @param: * @return: * @Date: 2024-04-07 18:47:25
-->
<template><div>{{ message }}</div>
</template><script>
export default {data() {return {message:'你打的'}}}
</script><style></style>

#package.json
{"name": "test-vue","version": "1.0.0","description": "","main": "index.js","scripts": {"start": "webpack serve --config ./config/webpack.dev.js ","build": "webpack --config ./config/webpack.dev.js"},"keywords": [],"author": "","license": "ISC","devDependencies": {"clean-webpack-plugin": "^4.0.0","html-webpack-plugin": "^5.6.0","terser-webpack-plugin": "^5.3.10","vue": "^2.7.16","webpack": "^5.91.0","webpack-cli": "^5.1.4","webpack-dev-server": "^5.0.4","webpack-merge": "^5.10.0","css-loader": "^7.0.0","vue-loader": "^15.4.2","vue-style-loader": "^4.1.3","vue-template-compiler": "^2.7.16"},"dependencies": {}
}

http://www.lryc.cn/news/334025.html

相关文章:

  • 【蓝桥杯嵌入式】第十三届省赛(第二场)
  • maya节点绕轴旋转
  • 如何水出第一篇SCI:SCI发刊历程,从0到1全过程经验分享!!!
  • SpringBoot表单防止重复提交
  • java面向对象.day17(什么是面向对象)
  • mysql处理并发简单示例
  • 顺序表——功能实现
  • 达梦导出工具dexp
  • Ubuntu 22.04安装新硬盘并启动时自动挂载
  • Mybatis中sqlSession.getMapper背后的原理
  • [环境配置]conda 64位安装32位python
  • 某虚假交友APP(信息窃取)逆向分析
  • 基于FPGA的按键消抖
  • 1.网络编程-网络协议
  • 代码+视频,手动绘制logistic回归预测模型校准曲线(Calibration curve)(2)
  • 金融数据_Scikit-Learn决策树(DecisionTreeClassifier)实例
  • bash的login shell与non-login shell,以及各自的初始化过程
  • 为什么苹果 Mac 电脑需要使用清理软件?
  • 33. UE5 RPG使用增强输入激活GameplayAbility(三)
  • speech to text 库FastASR交叉编译arm target的配置
  • WPS快速将插入Excle数据插入Word
  • Springboot 集成Rabbitmq之延时队列
  • 【云开发笔记NO.22】运用云原生产品打造技术中台
  • C++进阶(五) 哈希
  • 【算法基础】基于异或的排序、基于异或的经典面试题
  • HTML2:列表和表格
  • 用于无人机小型化设计的高精度温补晶振
  • 轨迹规划 | 图解最优控制LQR算法(附ROS C++/Python/Matlab仿真)
  • 工业视觉检测
  • wheeltec轮趣ROS教育机器人的网络连接