webpack.config.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. const path = require("path");
  2. const webpack = require("webpack");
  3. const HtmlWebpackPlugin = require("html-webpack-plugin");
  4. const { CleanWebpackPlugin } = require("clean-webpack-plugin");
  5. const CopyPlugin = require("copy-webpack-plugin");
  6. module.exports = {
  7. entry: {
  8. main: "./src/index.ts"
  9. },
  10. optimization: {
  11. splitChunks: {
  12. cacheGroups: {
  13. phaser: {
  14. test: /[\\/]node_modules[\\/]phaser[\\/]/,
  15. name: "phaser",
  16. chunks: "all",
  17. },
  18. phasereditor2d: {
  19. test: /[\\/]node_modules[\\/]@phasereditor2d[\\/]/,
  20. name: "phasereditor2d",
  21. chunks: "all",
  22. }
  23. }
  24. }
  25. },
  26. output: {
  27. path: path.resolve(__dirname, "dist"),
  28. filename: "[name]-[contenthash].bundle.js",
  29. assetModuleFilename: "asset-packs/[name]-[hash][ext][query]",
  30. },
  31. module: {
  32. rules: [
  33. {
  34. test: /\.tsx?$/,
  35. use: "ts-loader",
  36. exclude: /node_modules/,
  37. },
  38. {
  39. test: /\.json/,
  40. type: "asset/resource",
  41. exclude: /node_modules/,
  42. }
  43. ],
  44. },
  45. resolve: {
  46. extensions: [".tsx", ".ts", ".js"],
  47. },
  48. devServer: {
  49. historyApiFallback: true,
  50. allowedHosts: 'all',
  51. static: {
  52. directory: path.resolve(__dirname, "./dist"),
  53. },
  54. open: true,
  55. hot: true,
  56. port: 8080,
  57. },
  58. plugins: [
  59. new HtmlWebpackPlugin({
  60. template: path.join(__dirname, "src/index.html"),
  61. minify: false
  62. }),
  63. new CleanWebpackPlugin(),
  64. new CopyPlugin({
  65. patterns: [
  66. {
  67. from: "static",
  68. globOptions: {
  69. // asset pack files are imported in code as modules
  70. ignore: ["**/publicroot", "**/*-pack.json"]
  71. }
  72. }
  73. ]
  74. }),
  75. new webpack.HotModuleReplacementPlugin(),
  76. ]
  77. };