webpack.base.conf.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. const isProd = process.env.NODE_ENV === 'production'
  20. const isInternational = process.env.IS_INTERNATIONAL
  21. module.exports = {
  22. context: path.resolve(__dirname, '../'),
  23. entry: {
  24. app: './src/main.js'
  25. },
  26. output: {
  27. path: config.build.assetsRoot,
  28. filename: '[name].js',
  29. publicPath: process.env.NODE_ENV === 'production'
  30. ? config.build.assetsPublicPath
  31. : config.dev.assetsPublicPath
  32. },
  33. resolve: {
  34. extensions: ['.js', '.vue', '.json'],
  35. alias: {
  36. 'vue$': 'vue/dist/vue.esm.js',
  37. '@': resolve('src'),
  38. }
  39. },
  40. module: {
  41. rules: [
  42. ...(config.dev.useEslint ? [createLintingRule()] : []),
  43. {
  44. test: /\.vue$/,
  45. loader: 'vue-loader',
  46. options: vueLoaderConfig
  47. },
  48. {
  49. test: /\.js$/,
  50. loader: 'babel-loader',
  51. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  52. },
  53. {
  54. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  55. loader: 'url-loader',
  56. options: {
  57. limit: 10000,
  58. name: utils.assetsPath('v2/images/[path][name].[ext]'),
  59. publicPath: isProd ? 'https://4dscene.4dage.com/new4dkk/' : ''
  60. }
  61. },
  62. {
  63. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  64. loader: 'url-loader',
  65. options: {
  66. limit: 10000,
  67. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  68. }
  69. },
  70. {
  71. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  72. loader: 'url-loader',
  73. options: {
  74. limit: 10000,
  75. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  76. }
  77. }
  78. ]
  79. },
  80. node: {
  81. // prevent webpack from injecting useless setImmediate polyfill because Vue
  82. // source contains it (although only uses it if it's native).
  83. setImmediate: false,
  84. // prevent webpack from injecting mocks to Node native modules
  85. // that does not make sense for the client
  86. dgram: 'empty',
  87. fs: 'empty',
  88. net: 'empty',
  89. tls: 'empty',
  90. child_process: 'empty'
  91. }
  92. }