webpack.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // 执行环境
  2. const NODE_ENV = process.env.NODE_ENV;
  3. console.log("-----NODE_ENV===",NODE_ENV);
  4. var path = require('path')
  5. var webpack = require('webpack')
  6. module.exports = {
  7. entry: NODE_ENV == 'development' ? './src/main.js' : './src/qrcode/index.js',
  8. output: {
  9. path: path.resolve(__dirname, './dist'),
  10. publicPath: '/dist/',
  11. filename: 'qrcode.js',
  12. library: 'qrcode', // 指定的就是你使用require时的模块名
  13. libraryTarget: 'umd', // 指定输出格式
  14. umdNamedDefine: true // 会对 UMD 的构建过程中的 AMD 模块进行命名。否则就使用匿名的 define
  15. },
  16. module: {
  17. rules: [
  18. {
  19. test: /\.css$/,
  20. use: [
  21. 'vue-style-loader',
  22. 'css-loader'
  23. ],
  24. }, {
  25. test: /\.vue$/,
  26. loader: 'vue-loader',
  27. options: {
  28. loaders: {
  29. }
  30. // other vue-loader options go here
  31. }
  32. },
  33. {
  34. test: /\.js$/,
  35. loader: 'babel-loader',
  36. exclude: /node_modules/
  37. },
  38. {
  39. test: /\.(png|jpg|gif|svg)$/,
  40. loader: 'file-loader',
  41. options: {
  42. name: '[name].[ext]?[hash]'
  43. }
  44. }
  45. ]
  46. },
  47. resolve: {
  48. alias: {
  49. 'vue$': 'vue/dist/vue.esm.js'
  50. },
  51. extensions: ['*', '.js', '.vue', '.json']
  52. },
  53. devServer: {
  54. historyApiFallback: true,
  55. noInfo: true,
  56. overlay: true
  57. },
  58. performance: {
  59. hints: false
  60. },
  61. devtool: '#eval-source-map'
  62. }
  63. if (process.env.NODE_ENV === 'production') {
  64. module.exports.devtool = '#source-map'
  65. // http://vue-loader.vuejs.org/en/workflow/production.html
  66. module.exports.plugins = (module.exports.plugins || []).concat([
  67. new webpack.DefinePlugin({
  68. 'process.env': {
  69. NODE_ENV: '"production"'
  70. }
  71. }),
  72. new webpack.optimize.UglifyJsPlugin({
  73. sourceMap: true,
  74. compress: {
  75. warnings: false
  76. }
  77. }),
  78. new webpack.LoaderOptionsPlugin({
  79. minimize: true
  80. })
  81. ])
  82. }