无法判断 Vue 项目是处于调试模式还是 Visual Studio 的发布模式
Posted
技术标签:
【中文标题】无法判断 Vue 项目是处于调试模式还是 Visual Studio 的发布模式【英文标题】:Can't tell if Vue project is in debug more or release mode for Visual Studio 【发布时间】:2019-09-08 05:58:37 【问题描述】:我正在使用 Visual Studio 构建这个 Vue 应用程序,无论构建模式(调试/发布)如何,我仍然会在控制台中收到以下消息。
您正在开发模式下运行 Vue。 确保在部署生产时打开生产模式。 在https://vuejs.org/guide/deployment.html查看更多提示
有没有办法知道我是否真的处于发布模式,或者 Vue 是否只是在向我抛出该消息?
我知道这通常意味着 JS 文件已被缩小,Vue 应用程序是这种情况吗?
我不确定这是否有帮助,但这是我的 packages.json 文件
"name": "aspnetcore-vuejs",
"description": "ASP.NET Core & VueJS Starter project",
"author": "Mark Pieszak",
"scripts":
"dev": "cross-env ASPNETCORE_ENVIRONMENT=Development NODE_ENV=development dotnet run",
"build": "cross-env NODE_ENV=production webpack --progress --hide-modules",
"install": "webpack --config webpack.config.vendor.js"
,
"dependencies":
"@fortawesome/fontawesome-svg-core": "^1.2.4",
"@fortawesome/free-solid-svg-icons": "^5.3.1",
"@fortawesome/vue-fontawesome": "^0.1.1",
"axios": "^0.15.3",
"bootstrap-vue": "^2.0.0-rc.11",
"core-js": "^2.4.1",
"dayjs": "^1.7.5",
"font-awesome": "^4.6.3",
"material-design-icons-iconfont": "^3.0.3",
"vue": "^2.1.8",
"vue-infinite-loading": "^2.3.3",
"vue-masked-input": "^0.5.2",
"vue-router": "^2.1.1",
"vue-select": "^2.5.0",
"vue-server-renderer": "^2.1.8",
"vue-template-compiler": "^2.1.8",
"vuetify": "^1.2.3",
"vuex": "^2.1.1",
"vuex-router-sync": "^4.0.1"
,
"devDependencies":
"aspnet-webpack": "^2.0.1",
"babel-core": "^6.21.0",
"babel-loader": "^6.2.10",
"babel-plugin-transform-async-to-generator": "^6.22.0",
"babel-plugin-transform-runtime": "^6.15.0",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.18.0",
"babel-preset-stage-2": "^6.18.0",
"babel-register": "^6.18.0",
"bootstrap": "^4.1.3",
"cross-env": "^3.1.3",
"css-loader": "^0.26.1",
"event-source-polyfill": "^0.0.7",
"extract-text-webpack-plugin": "^2.0.0-rc",
"file-loader": "^0.9.0",
"jquery": "^2.2.1",
"node-sass": "^4.1.0",
"optimize-css-assets-webpack-plugin": "^1.3.1",
"regenerator-runtime": "^0.12.1",
"sass-loader": "^4.1.0",
"style-loader": "^0.13.1",
"url-loader": "^0.5.7",
"vue-loader": "^10.0.2",
"webpack": "^2.2.0",
"webpack-hot-middleware": "^2.12.2"
【问题讨论】:
你运行了什么脚本? (在 package.json 中) 不确定!这是我继承的前同事项目。我该如何检查?我将发布 packages.json 文件。 【参考方案1】:正如您发布的Vue.js deployment guide 所建议的那样,请检查您的webpack.config.js
并确保在部署应用程序时使用正确的mode
目标production
环境。
在 Webpack 4+ 中,你可以这样做:
module.exports =
mode: 'production'
但在 Webpack 3 及更早版本中,您需要使用 DefinePlugin
:
var webpack = require('webpack')
module.exports =
// ...
plugins: [
// ...
new webpack.DefinePlugin(
'process.env.NODE_ENV': JSON.stringify('production')
)
]
准备就绪后,您只需运行 npm run build
即可开始捆绑您的模块。
相关和有用的阅读材料:
Writing separate Webpack configurations for each environment。 Managing development and production builds with Webpack。 Introduction to NPM Scripts。【讨论】:
以上是关于无法判断 Vue 项目是处于调试模式还是 Visual Studio 的发布模式的主要内容,如果未能解决你的问题,请参考以下文章
Visual Studio 2010 认为它处于调试模式(但它设置为发布模式)