webpack.config.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. loader: "file-loader",
  43. options: {
  44. name: "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. headers: {
  59. "Access-Control-Allow-Origin": "*",
  60. "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
  61. "Access-Control-Allow-Headers": "X-Requested-With, Content-Type, Authorization"
  62. },
  63. },
  64. plugins: [new ConsoleRemotePlugin()],
  65. devtool: "source-map",
  66. optimization: {
  67. chunkIds: "named",
  68. minimize: false,
  69. },
  70. };
  71. if (process.env.NODE_ENV === "production") {
  72. config.mode = "production";
  73. config.output.filename = "[name]-bundle-[hash].min.js";
  74. config.output.chunkFilename = "[name]-chunk-[chunkhash].min.js";
  75. config.optimization.chunkIds = "deterministic";
  76. config.optimization.minimize = true;
  77. }
  78. export default config;