webpack.base.conf.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. 'use strict'
  2. const path = require('path')
  3. const utils = require('./utils')
  4. const config = require('../config')
  5. const vueLoaderConfig = require('./vue-loader.conf')
  6. require("babel-polyfill")
  7. function resolve (dir) {
  8. return path.join(__dirname, '..', dir)
  9. }
  10. const createLintingRule = () => ({
  11. test: /\.(js|vue)$/,
  12. loader: 'eslint-loader',
  13. enforce: 'pre',
  14. include: [resolve('src'), resolve('test')],
  15. options: {
  16. formatter: require('eslint-friendly-formatter'),
  17. emitWarning: !config.dev.showEslintErrorsInOverlay
  18. }
  19. })
  20. module.exports = {
  21. context: path.resolve(__dirname, '../'),
  22. entry: {
  23. app: './src/main.js'
  24. },
  25. //百度地图配置20190513
  26. externals: {
  27. "BMap": "BMap"
  28. },
  29. output: {
  30. path: config.build.assetsRoot,
  31. filename: '[name].js',
  32. publicPath: process.env.NODE_ENV === 'production'
  33. ? config.build.assetsPublicPath
  34. : config.dev.assetsPublicPath
  35. },
  36. resolve: {
  37. extensions: ['.js', '.vue', '.json'],
  38. alias: {
  39. 'vue$': 'vue/dist/vue.esm.js',
  40. '@': resolve('src'),
  41. }
  42. },
  43. module: {
  44. rules: [
  45. ...(config.dev.useEslint ? [createLintingRule()] : []),
  46. {
  47. test: /\.vue$/,
  48. loader: 'vue-loader',
  49. options: vueLoaderConfig
  50. },
  51. {
  52. test: /\.js$/,
  53. loader: 'babel-loader',
  54. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  55. },
  56. {
  57. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  58. loader: 'url-loader',
  59. options: {
  60. limit: 10000,
  61. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  62. }
  63. },
  64. {
  65. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  66. loader: 'url-loader',
  67. options: {
  68. limit: 10000,
  69. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  70. }
  71. },
  72. {
  73. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  74. loader: 'url-loader',
  75. options: {
  76. limit: 10000,
  77. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  78. }
  79. }
  80. ]
  81. },
  82. node: {
  83. // prevent webpack from injecting useless setImmediate polyfill because Vue
  84. // source contains it (although only uses it if it's native).
  85. setImmediate: false,
  86. // prevent webpack from injecting mocks to Node native modules
  87. // that does not make sense for the client
  88. dgram: 'empty',
  89. fs: 'empty',
  90. net: 'empty',
  91. tls: 'empty',
  92. child_process: 'empty'
  93. }
  94. }