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

webpack5启动项目报错:process is not defined

1.安装dotenv-webpack@8.1.0插件

2.在vue.config.js中配置

const Dotenv = require("dotenv-webpack")
const env = process.env.NODE_ENV || "development"plugins: [new DefinePlugin({}),new HtmlWebpackPlugin({template: path.resolve(__dirname, 'public/index.html'),filename: "index.html",templateParameters: {BASE_URL: `/`},}),//配置环境变量文件地址new Dotenv({path: `./.env.${env}`}),],

3.新建.env.development、.env.production文件

# just a flag
NODE_ENV = 'development'
STAGE = 'demo'
# LOCAL_URL = 'http://121.5.74.20/meapi/'# default port
port = 3001# base api
VUE_APP_BASE_API = '/apii'
# http://10.100.2.94:9011# debugger modal
VUE_APP_DEBUG = false

4.所有webpack5+vue2对应的插件及版本

{"name": "market-web","version": "0.1.0","private": true,"scripts": {"dev": "cross-env NODE_ENV=development webpack serve --config ./vue.config.js","build": "cross-env NODE_ENV=production webpack --config ./vue.config.js","lint": "vue-cli-service lint"},"dependencies": {"@babel/core": "^7.26.10","@babel/plugin-transform-runtime": "^7.26.10","@babel/preset-env": "^7.26.9","@babel/runtime-corejs3": "^7.27.0","axios": "^1.9.0","babel-loader": "^10.0.0","babel-polyfill": "^6.26.0","core-js": "^3.41.0","css-loader": "^7.1.2","dotenv-webpack": "^8.1.0","element-ui": "^2.15.3","html-webpack-plugin": "^5.6.3","mini-css-extract-plugin": "^2.9.2","nprogress": "^0.2.0","postcss-loader": "^8.1.1","postcss-pxtorem": "^5.1.1","sass": "^1.83.4","sass-loader": "^10.2.0","vue": "^2.6.14","vue-loader": "^15.10.1","vue-router": "^3.6.5","vue-seamless-scroll": "^1.1.23","vue-style-loader": "^4.1.3","vuex": "^3.6.2","webpack": "5.72.1","webpack-cli": "5.0.0","webpack-dev-server": "4.9.0"},"devDependencies": {"@babel/eslint-parser": "^7.12.16","@vue/cli-plugin-babel": "~5.0.0","@vue/cli-plugin-eslint": "~5.0.0","@vue/cli-service": "~5.0.0","cross-env": "^7.0.3","eslint": "^7.32.0","eslint-plugin-vue": "^8.0.3","vue-template-compiler": "^2.7.16"},"eslintConfig": {"root": true,"env": {"node": true},"extends": ["plugin:vue/essential","eslint:recommended"],"parserOptions": {"parser": "@babel/eslint-parser"},"rules": {}}
}

相关文章:

  • 【神经网络与深度学习】探索全连接网络如何学习数据的复杂模式,提取高层次特征
  • 游戏引擎学习第250天:# 清理DEBUG GUID
  • AI开发者的Docker实践:汉化(中文),更换镜像源,Dockerfile,部署Python项目
  • ZLG嵌入式笔记 | 移动硬盘和虚拟机的那些事儿
  • 【思考】欧洲大停电分析
  • Java导出带图片的Excel
  • ERP系统为何沦为“电子台账“?
  • TCP和UDP传输层协议
  • 归并排序算法
  • 第六章 流量特征分析-常见攻击事件 tomcat wp
  • Nginx — http、server、location模块下配置相同策略优先级问题
  • react-11使用vscode开发react相关扩展插件(相关的快捷生成)
  • 用Playwright自动化网页测试,不只是“点点点”
  • 大型连锁酒店集团数据湖应用示例
  • 深度解析 MindTorch:无缝迁移 PyTorch 到 MindSpore 的高效工具
  • Centos离线安装Docker(无坑版)
  • 硬件工程师面试常见问题(10)
  • [250430] Kali Linux 存储库密钥丢失导致所有用户无法正常更新 APT
  • 如何使用C语言手搓斐波那契数列?
  • 【数学建模国奖速成系列】优秀论文绘图复现代码(二)
  • 乌副总理:乌美签署矿产协议
  • 4月译著联合书单|心爱之物:热爱如何联结并塑造我们
  • 笔墨如何“构城”?上海美院城市山水晋京展出
  • 人民日报:在大有可为的时代大有作为
  • 朝鲜新型驱逐舰“崔贤”号进行多项武器试验
  • 东风着陆场做好各项搜救准备,迎接神舟十九号航天员天外归来