webpack.base.conf.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. const vuxLoader = require('vux-loader')
  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. // }
  38. // },
  39. // module: {
  40. // rules: [
  41. // ...(config.dev.useEslint ? [createLintingRule()] : []),
  42. // {
  43. // test: /\.vue$/,
  44. // loader: 'vue-loader',
  45. // options: vueLoaderConfig
  46. // },
  47. // {
  48. // test: /\.js$/,
  49. // loader: 'babel-loader',
  50. // include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  51. // },
  52. // {
  53. // test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  54. // loader: 'url-loader',
  55. // options: {
  56. // limit: 10000,
  57. // name: utils.assetsPath('img/[name].[hash:7].[ext]')
  58. // }
  59. // },
  60. // {
  61. // test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  62. // loader: 'url-loader',
  63. // options: {
  64. // limit: 10000,
  65. // name: utils.assetsPath('media/[name].[hash:7].[ext]')
  66. // }
  67. // },
  68. // {
  69. // test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  70. // loader: 'url-loader',
  71. // options: {
  72. // limit: 10000,
  73. // name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  74. // }
  75. // }
  76. // ]
  77. // },
  78. // node: {
  79. // // prevent webpack from injecting useless setImmediate polyfill because Vue
  80. // // source contains it (although only uses it if it's native).
  81. // setImmediate: false,
  82. // // prevent webpack from injecting mocks to Node native modules
  83. // // that does not make sense for the client
  84. // dgram: 'empty',
  85. // fs: 'empty',
  86. // net: 'empty',
  87. // tls: 'empty',
  88. // child_process: 'empty'
  89. // }
  90. // }
  91. const webpackConfig = {
  92. context: path.resolve(__dirname, '../'),
  93. entry: {
  94. app: './src/main.js'
  95. },
  96. output: {
  97. path: config.build.assetsRoot,
  98. filename: '[name].js',
  99. publicPath: process.env.NODE_ENV === 'production'
  100. ? config.build.assetsPublicPath
  101. : config.dev.assetsPublicPath
  102. },
  103. resolve: {
  104. extensions: ['.js', '.vue', '.json'],
  105. alias: {
  106. 'vue$': 'vue/dist/vue.esm.js',
  107. '@': resolve('src'),
  108. }
  109. },
  110. module: {
  111. rules: [
  112. ...(config.dev.useEslint ? [createLintingRule()] : []),
  113. {
  114. test: /\.vue$/,
  115. loader: 'vue-loader',
  116. options: vueLoaderConfig
  117. },
  118. {
  119. test: /\.js$/,
  120. loader: 'babel-loader',
  121. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  122. },
  123. {
  124. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  125. loader: 'url-loader',
  126. options: {
  127. limit: 10000,
  128. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  129. }
  130. },
  131. {
  132. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  133. loader: 'url-loader',
  134. options: {
  135. limit: 10000,
  136. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  137. }
  138. },
  139. {
  140. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  141. loader: 'url-loader',
  142. options: {
  143. limit: 10000,
  144. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  145. }
  146. }
  147. ]
  148. },
  149. node: {
  150. // prevent webpack from injecting useless setImmediate polyfill because Vue
  151. // source contains it (although only uses it if it's native).
  152. setImmediate: false,
  153. // prevent webpack from injecting mocks to Node native modules
  154. // that does not make sense for the client
  155. dgram: 'empty',
  156. fs: 'empty',
  157. net: 'empty',
  158. tls: 'empty',
  159. child_process: 'empty'
  160. }
  161. }
  162. module.exports = vuxLoader.merge(webpackConfig, {
  163. plugins: ['vux-ui']
  164. })