javascript - How to configure webpack in the production environment so that Vue Devtools can be turned off.
phpcn_u1582
phpcn_u1582 2017-05-19 10:46:44
0
1
2076

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_u1582
phpcn_u1582

reply all(1)
曾经蜡笔没有小新

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;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template