webpack.base.conf.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. let assetsPublicPath = '/'
  20. let assetsApp = './src/main.js'
  21. let assetsRoot = path.resolve(__dirname, '../dist')
  22. if(process.env.NODE_ENV === 'production'){
  23. assetsApp = config.build.assetsApp
  24. assetsPublicPath = config.build.assetsPublicPath
  25. } else if(process.env.NODE_ENV === 'define'){
  26. assetsApp = config.define.assetsApp
  27. assetsRoot = config.define.assetsRoot
  28. assetsPublicPath = config.define.assetsPublicPath
  29. } else if(!process.env.NODE_ENV ||process.env.NODE_ENV === 'development') {
  30. assetsApp = config.dev.assetsApp
  31. assetsPublicPath = config.dev.assetsPublicPath
  32. }
  33. console.log(`------------------------------
  34. NODE_ENV : ${process.env.NODE_ENV}
  35. assetsApp : ${assetsApp}
  36. assetsRoot : ${assetsRoot}
  37. assetsPublicPath : ${assetsPublicPath}
  38. ------------------------------`)
  39. module.exports = {
  40. context: path.resolve(__dirname, '../'),
  41. entry: {
  42. app: assetsApp
  43. },
  44. output: {
  45. path: assetsRoot,
  46. filename: '[name].js',
  47. publicPath: assetsPublicPath
  48. },
  49. resolve: {
  50. extensions: ['.js', '.vue', '.json'],
  51. alias: {
  52. 'vue$': 'vue/dist/vue.esm.js',
  53. '@': resolve('src')
  54. }
  55. },
  56. module: {
  57. rules: [
  58. ...(config.dev.useEslint ? [createLintingRule()] : []),
  59. {
  60. test: /\.vue$/,
  61. loader: 'vue-loader',
  62. options: vueLoaderConfig
  63. },
  64. {
  65. test: /\.js$/,
  66. loader: 'babel-loader',
  67. include: [resolve('src'), resolve('test') ,resolve('node_modules/webpack-dev-server/client')]
  68. },
  69. {
  70. test: /\.svg$/,
  71. loader: 'svg-sprite-loader',
  72. include: [resolve('src/icons')],
  73. options: {
  74. symbolId: 'icon-[name]'
  75. }
  76. },
  77. {
  78. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  79. loader: 'url-loader',
  80. exclude: [resolve('src/icons')],
  81. options: {
  82. limit: 10000,
  83. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  84. }
  85. },
  86. {
  87. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  88. loader: 'url-loader',
  89. options: {
  90. limit: 10000,
  91. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  92. }
  93. },
  94. {
  95. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  96. loader: 'url-loader',
  97. options: {
  98. limit: 10000,
  99. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  100. }
  101. }
  102. ]
  103. },
  104. node: {
  105. // prevent webpack from injecting useless setImmediate polyfill because Vue
  106. // source contains it (although only uses it if it's native).
  107. setImmediate: false,
  108. // prevent webpack from injecting mocks to Node native modules
  109. // that does not make sense for the client
  110. dgram: 'empty',
  111. fs: 'empty',
  112. net: 'empty',
  113. tls: 'empty',
  114. child_process: 'empty'
  115. }
  116. }