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