Adrian Krebs
Adrian Krebs

Reputation: 4387

How can I disable source maps in production for a vue.js app?

My app is created with the vue cli. I can't find any option to disable source maps in production. The npm build step in my package.json looks like this:

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

In angular, i can just add --prod to my build step to make it work. Is there any such option for vue.js? Or do I have to change the webpack config (which is hidden by the cli)?

Upvotes: 77

Views: 43528

Answers (4)

djaber atia
djaber atia

Reputation: 101

set devTool:false like this:

module.exports = {
  transpileDependencies: ["vuetify"],
  configureWebpack: {
     devtool: process.env.NODE_ENV === "development" ? "eval" : false,

    module: {},
  },

  devServer: {
    port: 8080,
    open: true,
  },
};

Upvotes: 1

Parzibyte
Parzibyte

Reputation: 1598

In my case the file vue.config.js wasn't taking effect. I had to change config/index.js changing productionSourceMap to false.

Please note that the project was generated a time ago. For the record, I am using a template from Vuetify.

'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
  }
}

Upvotes: 1

solmans
solmans

Reputation: 575

like @yuriy636 's answer, if you want only for production :

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

Upvotes: 18

yuriy636
yuriy636

Reputation: 11661

You make changes to the internal webpack config with the vue.config.js file at the project root (you may need to create it manually).

There is a productionSourceMap option so you can disable source maps when building for production:

module.exports = {
  productionSourceMap: false
};

Upvotes: 168

Related Questions