search

Home  >  Q&A  >  body text

javascript - How to configure webpack in the production environment so that Vue Devtools can be turned off.

The project is about to go into production, but I found that the production environment can still be seen in the debugging mode of chrome.vue-devtoolsHow should I configure my webpack?
Note: My project is useless vue-cli is simply webpack vue-loader packaging. The following is my code:

var webpack = require("webpack");
var path = require("path");

module.exports = {
  /**
   * devtool
   * 开发者工具 debug用 生产环境要取消
   */
  cache: false,
  debug: false,
  /**
   * webpack 基础配置
   */
  entry: __dirname + "/../app/main.js",  //入口文件
  output: {
    filename: "build.js",
    path: path.resolve(__dirname, "../dist"),
    publicPath: '/dist/'
  },

  /**
   * module
   */
  module: {
    loaders: [
      {
        test: /\.vue$/,
        loader: 'vue'
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loader: 'babel',
      },
      {
        test: /\.css$/,
        loader: 'style-loader!css-loader',
      },
      {
        test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
        loader: 'url',
        query: {
          limit: 6000,
          name: 'assets/[name]_[hash:8].[ext]'
        }
      }
    ]
  },
  vue: {
    loaders: {
      js: 'babel',
    }
  },
  resolve: {
    alias: {
      'vue$': 'vue/dist/vue.js'
    }
  },
  babel: {
    presets: ['es2015', 'stage-0'],
    plugins: ['transform-runtime']
  }
};
if (process.env.NODE_ENV === 'production') {
  module.exports.devtool = false;
  module.exports.plugins = [
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV: JSON.stringify("production")
      }
    }),
    new webpack.optimize.UglifyJsPlugin({
      compress: {
        warnings: false
      }
    }),
    new webpack.optimize.OccurenceOrderPlugin()
  ];
} else {
  module.exports.devtool = '#source-map'
}
phpcn_u1582phpcn_u15822748 days ago2077

reply all(1)I'll reply

  • 曾经蜡笔没有小新

    曾经蜡笔没有小新2017-05-19 10:48:44

    Solved it myself.

    const isDebug_mode = process.env.NODE_ENV !== 'production';
    Vue.config.debug = isDebug_mode;
    Vue.config.devtools = isDebug_mode;
    Vue.config.productionTip = isDebug_mode;

    reply
    0
  • Cancelreply