webpack.base.conf.js 2.3 KB

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