webpack.config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. const fs = require('fs')
  2. const path = require('path')
  3. const webpack = require('webpack')
  4. const VueLoaderPlugin = require('vue-loader/lib/plugin')
  5. module.exports = {
  6. mode: 'development',
  7. entry: fs.readdirSync(__dirname).reduce((entries, dir) => {
  8. const fullDir = path.join(__dirname, dir)
  9. const entry = path.join(fullDir, 'app.js')
  10. if (fs.statSync(fullDir).isDirectory() && fs.existsSync(entry)) {
  11. entries[dir] = ['webpack-hot-middleware/client', entry]
  12. }
  13. return entries
  14. }, {}),
  15. output: {
  16. path: path.join(__dirname, '__build__'),
  17. filename: '[name].js',
  18. chunkFilename: '[id].chunk.js',
  19. publicPath: '/__build__/'
  20. },
  21. module: {
  22. rules: [
  23. { test: /\.js$/, exclude: /node_modules/, use: ['babel-loader'] },
  24. { test: /\.vue$/, use: ['vue-loader'] },
  25. { test: /\.css$/, use: ['vue-style-loader', 'css-loader'] }
  26. ]
  27. },
  28. resolve: {
  29. alias: {
  30. vuex: path.resolve(__dirname, '../src/index.js')
  31. }
  32. },
  33. optimization: {
  34. splitChunks: {
  35. cacheGroups: {
  36. vendors: {
  37. name: 'shared',
  38. filename: 'shared.js',
  39. chunks: 'initial'
  40. }
  41. }
  42. }
  43. },
  44. plugins: [
  45. new VueLoaderPlugin(),
  46. new webpack.HotModuleReplacementPlugin(),
  47. new webpack.NoEmitOnErrorsPlugin(),
  48. new webpack.DefinePlugin({
  49. __DEV__: JSON.stringify(true),
  50. 'process.env': {
  51. NODE_ENV: JSON.stringify(process.env.NODE_ENV)
  52. }
  53. })
  54. ]
  55. }