webpack.base.conf.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. var webpack=require('webpack')
  2. 'use strict'
  3. const path = require('path')
  4. const utils = require('./utils')
  5. const config = require('../config')
  6. const vueLoaderConfig = require('./vue-loader.conf')
  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. test:/\.scss$/,
  78. use:['style-loader','css-loader','sass-loader']
  79. }
  80. ]
  81. },
  82. node: {
  83. // prevent webpack from injecting useless setImmediate polyfill because Vue
  84. // source contains it (although only uses it if it's native).
  85. setImmediate: false,
  86. // prevent webpack from injecting mocks to Node native modules
  87. // that does not make sense for the client
  88. dgram: 'empty',
  89. fs: 'empty',
  90. net: 'empty',
  91. tls: 'empty',
  92. child_process: 'empty'
  93. }
  94. }