webpack.base.conf.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. }
  46. },
  47. plugins: [
  48. new webpack.ProvidePlugin({
  49. $: "jquery",
  50. jQuery: "jquery"
  51. })
  52. ],
  53. module: {
  54. rules: [
  55. ...(config.dev.useEslint ? [createLintingRule()] : []),
  56. {
  57. test: /\.vue$/,
  58. loader: 'vue-loader',
  59. options: vueLoaderConfig
  60. },
  61. {
  62. test: /\.js$/,
  63. loader: 'babel-loader',
  64. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  65. },
  66. {
  67. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  68. loader: 'url-loader',
  69. options: {
  70. limit: 10000,
  71. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  72. }
  73. },
  74. {
  75. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  76. loader: 'url-loader',
  77. options: {
  78. limit: 10000,
  79. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  80. }
  81. },
  82. {
  83. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  84. loader: 'url-loader',
  85. options: {
  86. limit: 10000,
  87. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  88. }
  89. }
  90. ]
  91. },
  92. node: {
  93. // prevent webpack from injecting useless setImmediate polyfill because Vue
  94. // source contains it (although only uses it if it's native).
  95. setImmediate: false,
  96. // prevent webpack from injecting mocks to Node native modules
  97. // that does not make sense for the client
  98. dgram: 'empty',
  99. fs: 'empty',
  100. net: 'empty',
  101. tls: 'empty',
  102. child_process: 'empty'
  103. }
  104. }