webpack.base.conf.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 { VueLoaderPlugin } = require('vue-loader')
  7. const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin')
  8. function resolve (dir) {
  9. return path.join(__dirname, '..', dir)
  10. }
  11. const createLintingRule = () => ({
  12. test: /\.(js|vue)$/,
  13. loader: 'eslint-loader',
  14. enforce: 'pre',
  15. include: [resolve('src'), resolve('test')],
  16. options: {
  17. formatter: require('eslint-friendly-formatter'),
  18. emitWarning: !config.dev.showEslintErrorsInOverlay
  19. }
  20. })
  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. plugins: [
  34. new VueLoaderPlugin(),
  35. new MonacoWebpackPlugin()
  36. ],
  37. resolve: {
  38. extensions: ['.js', '.vue', '.json'],
  39. alias: {
  40. 'vue$': 'vue/dist/vue.esm.js',
  41. '@': resolve('src'),
  42. }
  43. },
  44. module: {
  45. rules: [
  46. ...(config.dev.useEslint ? [createLintingRule()] : []),
  47. {
  48. test: /\.vue$/,
  49. loader: 'vue-loader',
  50. options: vueLoaderConfig
  51. },
  52. {
  53. test: /\.js$/,
  54. loader: 'babel-loader',
  55. include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
  56. },
  57. {
  58. test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
  59. loader: 'url-loader',
  60. options: {
  61. limit: 10000,
  62. name: utils.assetsPath('img/[name].[hash:7].[ext]')
  63. }
  64. },
  65. {
  66. test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
  67. loader: 'url-loader',
  68. options: {
  69. limit: 10000,
  70. name: utils.assetsPath('media/[name].[hash:7].[ext]')
  71. }
  72. },
  73. {
  74. test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
  75. loader: 'url-loader',
  76. options: {
  77. limit: 10000,
  78. name: utils.assetsPath('fonts/[name].[hash:7].[ext]')
  79. }
  80. }
  81. ]
  82. },
  83. node: {
  84. // prevent webpack from injecting useless setImmediate polyfill because Vue
  85. // source contains it (although only uses it if it's native).
  86. setImmediate: false,
  87. // prevent webpack from injecting mocks to Node native modules
  88. // that does not make sense for the client
  89. dgram: 'empty',
  90. fs: 'empty',
  91. net: 'empty',
  92. tls: 'empty',
  93. child_process: 'empty'
  94. }
  95. }