如何在生产中禁用 vue.js 应用程序的源映射?

问题描述 投票:0回答:4

我的应用程序是使用

vue cli
创建的。我找不到任何在生产中禁用源映射的选项。 我的
npm build
中的
package.json
步骤如下所示:

"build": "vue-cli-service build",

在角度中,我只需将

--prod
添加到我的构建步骤即可使其工作。
vue.js
有这样的选择吗?或者我是否必须更改
webpack
配置(被 cli 隐藏)?

webpack vue.js
4个回答
165
投票

您可以使用项目根目录下的

vue.config.js
文件对内部 webpack 配置进行更改(您可能需要手动创建它)。

有一个

productionSourceMap
选项,因此您可以在构建生产时禁用源映射:

module.exports = {
  productionSourceMap: false
};

18
投票

就像@yuriy636的答案,如果你只想用于生产:

module.exports = {
  productionSourceMap: process.env.NODE_ENV != 'production'
};

1
投票

就我而言,文件

vue.config.js
未生效。我必须将
config/index.js
更改为
productionSourceMap
请注意,该项目是不久前生成的。作为记录,我使用的是 Vuetify 的模板。

false



0
投票

'use strict' // Template version: 1.2.8 // see http://vuejs-templates.github.io/webpack for documentation. const path = require('path') module.exports = { dev: { // Paths assetsSubDirectory: 'static', assetsPublicPath: '/', proxyTable: {}, // Various Dev Server settings host: 'localhost', // can be overwritten by process.env.HOST port: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determined autoOpenBrowser: false, errorOverlay: true, notifyOnErrors: true, poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions- /** * Source Maps */ // https://webpack.js.org/configuration/devtool/#development devtool: 'cheap-module-eval-source-map', // If you have problems debugging vue-files in devtools, // set this to false - it *may* help // https://vue-loader.vuejs.org/en/options.html#cachebusting cacheBusting: true, cssSourceMap: true, }, build: { // Template for index.html index: path.resolve(__dirname, '../dist/index.html'), // Paths assetsRoot: path.resolve(__dirname, '../dist'), assetsSubDirectory: './', assetsPublicPath: './', /** * Source Maps */ productionSourceMap: false, // <---- Here // https://webpack.js.org/configuration/devtool/#production devtool: '#source-map', // Gzip off by default as many popular static hosts such as // Surge or Netlify already gzip all static assets for you. // Before setting to `true`, make sure to: // npm install --save-dev compression-webpack-plugin productionGzip: false, productionGzipExtensions: ['js', 'css'], // Run the build command with an extra argument to // View the bundle analyzer report after build finishes: // `npm run build --report` // Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report } }

© www.soinside.com 2019 - 2024. All rights reserved.