webpack.config.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* eslint-env node */
  2. import { Configuration as WebpackConfiguration } from "webpack";
  3. import { Configuration as WebpackDevServerConfiguration } from "webpack-dev-server";
  4. import * as path from "path";
  5. import { ConsoleRemotePlugin } from "@openshift-console/dynamic-plugin-sdk-webpack";
  6. interface Configuration extends WebpackConfiguration {
  7. devServer?: WebpackDevServerConfiguration;
  8. }
  9. const config: Configuration = {
  10. mode: "development",
  11. // No regular entry points. The remote container entry is handled by ConsoleRemotePlugin.
  12. entry: {},
  13. context: path.resolve(__dirname, "src"),
  14. output: {
  15. path: path.resolve(__dirname, "dist"),
  16. filename: "[name]-bundle.js",
  17. chunkFilename: "[name]-chunk.js",
  18. },
  19. resolve: {
  20. extensions: [".ts", ".tsx", ".js", ".jsx"],
  21. },
  22. module: {
  23. rules: [
  24. {
  25. test: /\.(jsx?|tsx?)$/,
  26. exclude: /node_modules/,
  27. use: [
  28. {
  29. loader: "ts-loader",
  30. options: {
  31. configFile: path.resolve(__dirname, "tsconfig.json"),
  32. },
  33. },
  34. ],
  35. },
  36. {
  37. test: /\.css$/,
  38. use: ["style-loader", "css-loader"],
  39. },
  40. {
  41. test: /\.(png|jpg|jpeg|gif|svg|woff2?|ttf|eot|otf)(\?.*$|$)/,
  42. type: 'asset/resource',
  43. generator: {
  44. filename: 'assets/[name].[ext]',
  45. },
  46. },
  47. {
  48. test: /\.m?js/,
  49. resolve: {
  50. fullySpecified: false,
  51. },
  52. },
  53. ],
  54. },
  55. devServer: {
  56. static: './dist',
  57. port: 9001,
  58. // Allow bridge running in a container to connect to the plugin dev server.
  59. allowedHosts: 'all',
  60. headers: {
  61. "Access-Control-Allow-Origin": "*",
  62. "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
  63. "Access-Control-Allow-Headers": "X-Requested-With, Content-Type, Authorization"
  64. },
  65. devMiddleware: {
  66. writeToDisk: true,
  67. },
  68. },
  69. plugins: [new ConsoleRemotePlugin()],
  70. devtool: "source-map",
  71. optimization: {
  72. chunkIds: "named",
  73. minimize: false,
  74. },
  75. };
  76. if (process.env.NODE_ENV === "production") {
  77. config.mode = "production";
  78. config.output.filename = "[name]-bundle-[hash].min.js";
  79. config.output.chunkFilename = "[name]-chunk-[chunkhash].min.js";
  80. config.optimization.chunkIds = "deterministic";
  81. config.optimization.minimize = true;
  82. config.devtool = false;
  83. }
  84. export default config;