webpack.base.conf.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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: /\.s[ac]ss$/i,
  53. use: [
  54. // Creates `style` nodes from JS strings
  55. 'style-loader',
  56. // Translates CSS into CommonJS
  57. 'css-loader',
  58. // Compiles Sass to CSS
  59. 'sass-loader',
  60. ],
  61. },
  62. {
  63. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  64. loader: 'url-loader',
  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. node: {
  89. // prevent webpack from injecting useless setImmediate polyfill because Vue
  90. // source contains it (although only uses it if it's native).
  91. setImmediate: false,
  92. // prevent webpack from injecting mocks to Node native modules
  93. // that does not make sense for the client
  94. dgram: 'empty',
  95. fs: 'empty',
  96. net: 'empty',
  97. tls: 'empty',
  98. child_process: 'empty'
  99. },
  100. // externals: {
  101. // 'vue': 'Vue',
  102. // 'vue-router': 'VueRouter'
  103. // }
  104. }