webpack.config.js 1.6 KB

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