webpack.prod.config.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. const webpack = require("webpack");
  2. const path = require("path");
  3. const BundleAnalyzerPlugin =
  4. require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
  5. module.exports = {
  6. mode: "production",
  7. entry: { "excalidraw-utils.min": "./index.js" },
  8. output: {
  9. path: path.resolve(__dirname, "dist"),
  10. filename: "[name].js",
  11. library: "ExcalidrawUtils",
  12. libraryTarget: "umd",
  13. },
  14. resolve: {
  15. extensions: [".tsx", ".ts", ".js", ".css", ".scss"],
  16. },
  17. optimization: {
  18. runtimeChunk: false,
  19. },
  20. module: {
  21. rules: [
  22. {
  23. test: /\.(sa|sc|c)ss$/,
  24. exclude: /node_modules/,
  25. use: ["style-loader", { loader: "css-loader" }, "sass-loader"],
  26. },
  27. {
  28. test: /\.(ts|tsx|js)$/,
  29. use: [
  30. {
  31. loader: "ts-loader",
  32. options: {
  33. transpileOnly: true,
  34. configFile: path.resolve(__dirname, "../tsconfig.prod.json"),
  35. },
  36. },
  37. {
  38. loader: "babel-loader",
  39. options: {
  40. presets: [
  41. "@babel/preset-env",
  42. ["@babel/preset-react", { runtime: "automatic" }],
  43. "@babel/preset-typescript",
  44. ],
  45. plugins: [["@babel/plugin-transform-runtime"]],
  46. },
  47. },
  48. ],
  49. },
  50. ],
  51. },
  52. plugins: [
  53. new webpack.optimize.LimitChunkCountPlugin({
  54. maxChunks: 1,
  55. }),
  56. ...(process.env.ANALYZER === "true" ? [new BundleAnalyzerPlugin()] : []),
  57. ],
  58. };