webpack.base.conf.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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:['babel-polyfill','./src/main.js']
  24. },
  25. externals: {
  26. vue: 'Vue',
  27. axios: 'axios',
  28. 'vue-router': 'VueRouter',
  29. 'element-ui': 'ELEMENT',
  30. moment: 'moment',
  31. // 'babel-polyfill': 'BabelPolyfill'
  32. },
  33. output: {
  34. path: config.build.assetsRoot,
  35. filename: '[name].js',
  36. publicPath: process.env.NODE_ENV === 'production'
  37. ? config.build.assetsPublicPath
  38. : config.dev.assetsPublicPath
  39. },
  40. resolve: {
  41. extensions: ['.js', '.vue', '.json'],
  42. alias: {
  43. 'vue$': 'vue/dist/vue.esm.js',
  44. '@': resolve('src'),
  45. 'vendor': path.resolve(__dirname, 'src/vendor') // 添加一个别名
  46. }
  47. },
  48. plugins: [
  49. new webpack.ProvidePlugin({
  50. $: "jquery",
  51. jQuery: "jquery"
  52. })
  53. ],
  54. module: {
  55. rules: [
  56. ...(config.dev.useEslint ? [createLintingRule()] : []),
  57. {
  58. test: /\.vue$/,
  59. loader: 'vue-loader',
  60. options: vueLoaderConfig
  61. },
  62. {
  63. test: /\.(js|vue)$/,
  64. loader: 'eslint-loader',
  65. enforce: 'pre',
  66. include: [resolve('src'), resolve('test')],
  67. options: {
  68. formatter: require('eslint-friendly-formatter'),
  69. // 不符合Eslint规则时只警告(默认运行出错)
  70. // emitWarning: !config.dev.showEslintErrorsInOverlay
  71. }
  72. },
  73. {
  74. test: /\.js$/,
  75. loader: 'babel-loader',
  76. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  77. },
  78. {
  79. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  80. loader: 'url-loader',
  81. options: {
  82. limit: 10000,
  83. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  84. }
  85. },
  86. {
  87. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  88. loader: 'url-loader',
  89. options: {
  90. limit: 10000,
  91. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  92. }
  93. },
  94. {
  95. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  96. loader: 'url-loader',
  97. options: {
  98. limit: 10000,
  99. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  100. }
  101. }
  102. ]
  103. },
  104. node: {
  105. // prevent webpack from injecting useless setImmediate polyfill because Vue
  106. // source contains it (although only uses it if it's native).
  107. setImmediate: false,
  108. // prevent webpack from injecting mocks to Node native modules
  109. // that does not make sense for the client
  110. dgram: 'empty',
  111. fs: 'empty',
  112. net: 'empty',
  113. tls: 'empty',
  114. child_process: 'empty'
  115. }
  116. }