webpack.base.conf.js 2.8 KB

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