webpack.base.conf.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. function resolve (dir) {
  7. return path.join(__dirname, '..', dir)
  8. }
  9. module.exports = {
  10. context: path.resolve(__dirname, '../'),
  11. entry: {
  12. // 兼容ie11的设置
  13. app: ['babel-polyfill','./src/main.js']
  14. },
  15. output: {
  16. path: config.build.assetsRoot,
  17. filename: '[name].js',
  18. publicPath: process.env.NODE_ENV === 'production'
  19. ? config.build.assetsPublicPath
  20. : config.dev.assetsPublicPath
  21. },
  22. resolve: {
  23. extensions: ['.js', '.vue', '.json'],
  24. alias: {
  25. 'vue$': 'vue/dist/vue.esm.js',
  26. '@': resolve('src'),
  27. }
  28. },
  29. module: {
  30. rules: [
  31. {
  32. test: /\.vue$/,
  33. loader: 'vue-loader',
  34. options: vueLoaderConfig
  35. },
  36. {
  37. test: /\.js$/,
  38. loader: 'babel-loader',
  39. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  40. },
  41. {
  42. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  43. loader: 'url-loader',
  44. options: {
  45. limit: 10000,
  46. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  47. }
  48. },
  49. {
  50. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  51. loader: 'url-loader',
  52. options: {
  53. limit: 10000,
  54. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  55. }
  56. },
  57. {
  58. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  59. loader: 'url-loader',
  60. options: {
  61. limit: 10000,
  62. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  63. }
  64. }
  65. ]
  66. },
  67. node: {
  68. // prevent webpack from injecting useless setImmediate polyfill because Vue
  69. // source contains it (although only uses it if it's native).
  70. setImmediate: false,
  71. // prevent webpack from injecting mocks to Node native modules
  72. // that does not make sense for the client
  73. dgram: 'empty',
  74. fs: 'empty',
  75. net: 'empty',
  76. tls: 'empty',
  77. child_process: 'empty'
  78. }
  79. }