webpack.base.conf.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. 'use strict'
  2. const path = require('path')
  3. const webpack = require('webpack')
  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. // externals:{
  33. // 'vue':'Vue',
  34. // 'element-ui':'ELEMENT',
  35. // 'moment':'moment'
  36. // },
  37. plugins: [
  38. // http://vuejs.github.io/vue-loader/en/workflow/production.html
  39. new webpack.DefinePlugin({
  40. 'BASE_URL_ENV': JSON.stringify(process.env.base_url)
  41. })
  42. ],
  43. resolve: {
  44. extensions: ['.js', '.vue', '.json'],
  45. alias: {
  46. 'vue$': 'vue/dist/vue.esm.js',
  47. '@': resolve('src'),
  48. 'imgs':resolve('src/assets/imgs')
  49. }
  50. },
  51. module: {
  52. rules: [
  53. ...(config.dev.useEslint ? [createLintingRule()] : []),
  54. {
  55. test: /\.vue$/,
  56. loader: 'vue-loader',
  57. options: vueLoaderConfig
  58. },
  59. {
  60. test: /\.js$/,
  61. loader: 'babel-loader',
  62. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  63. },
  64. {
  65. test: /\.svg$/,
  66. loader: 'svg-sprite-loader',
  67. include: [resolve('src/icons')],
  68. options: {
  69. symbolId: 'icon-[name]'
  70. }
  71. },
  72. {
  73. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  74. loader: 'url-loader',
  75. exclude: [resolve('src/icons')],
  76. options: {
  77. limit: 10000,
  78. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  79. }
  80. },
  81. {
  82. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  83. loader: 'url-loader',
  84. options: {
  85. limit: 10000,
  86. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  87. }
  88. },
  89. {
  90. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  91. loader: 'url-loader',
  92. options: {
  93. limit: 10000,
  94. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  95. }
  96. }
  97. ]
  98. },
  99. node: {
  100. // prevent webpack from injecting useless setImmediate polyfill because Vue
  101. // source contains it (although only uses it if it's native).
  102. setImmediate: false,
  103. // prevent webpack from injecting mocks to Node native modules
  104. // that does not make sense for the client
  105. dgram: 'empty',
  106. fs: 'empty',
  107. net: 'empty',
  108. tls: 'empty',
  109. child_process: 'empty'
  110. }
  111. }