webpack.base.conf.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. const webpack = require('webpack')
  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. externals: {
  26. 'BMap': 'BMap',
  27. 'BMap_Symbol_SHAPE_POINT': 'BMap_Symbol_SHAPE_POINT',
  28. vue: 'Vue',
  29. axios: 'axios',
  30. 'vue-router': 'VueRouter',
  31. 'element-ui': 'ELEMENT',
  32. swiper: 'Swiper'
  33. },
  34. output: {
  35. path: config.build.assetsRoot,
  36. filename: '[name].js',
  37. publicPath: process.env.NODE_ENV === 'production'
  38. ? config.build.assetsPublicPath
  39. : config.dev.assetsPublicPath
  40. },
  41. resolve: {
  42. extensions: ['.js', '.vue', '.json'],
  43. alias: {
  44. 'vue$': 'vue/dist/vue.esm.js',
  45. '@': resolve('src'),
  46. 'jquery': path.resolve(__dirname, '../node_modules/jquery/src/jquery'),
  47. 'directives': path.resolve(__dirname, '../src/directives')
  48. }
  49. },
  50. module: {
  51. rules: [
  52. ...(config.dev.useEslint ? [createLintingRule()] : []),
  53. {
  54. test: /\.vue$/,
  55. loader: 'vue-loader',
  56. options: vueLoaderConfig
  57. },
  58. {
  59. test: /\.js$/,
  60. loader: 'babel-loader',
  61. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  62. },
  63. {
  64. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  65. loader: 'url-loader',
  66. options: {
  67. limit: 10000,
  68. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  69. }
  70. },
  71. {
  72. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  73. loader: 'url-loader',
  74. options: {
  75. limit: 10000,
  76. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  77. }
  78. },
  79. {
  80. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  81. loader: 'url-loader',
  82. options: {
  83. limit: 10000,
  84. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  85. }
  86. }
  87. ]
  88. },
  89. node: {
  90. // prevent webpack from injecting useless setImmediate polyfill because Vue
  91. // source contains it (although only uses it if it's native).
  92. setImmediate: false,
  93. // prevent webpack from injecting mocks to Node native modules
  94. // that does not make sense for the client
  95. dgram: 'empty',
  96. fs: 'empty',
  97. net: 'empty',
  98. tls: 'empty',
  99. child_process: 'empty'
  100. }
  101. }