webpack.base.conf.js 2.3 KB

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