common.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright (c) Meta Platforms, Inc. and affiliates.
  2. // All rights reserved.
  3. // This source code is licensed under the license found in the
  4. // LICENSE file in the root directory of this source tree.
  5. const { resolve } = require("path");
  6. const HtmlWebpackPlugin = require("html-webpack-plugin");
  7. const FriendlyErrorsWebpackPlugin = require("friendly-errors-webpack-plugin");
  8. const CopyPlugin = require("copy-webpack-plugin");
  9. const webpack = require("webpack");
  10. module.exports = {
  11. entry: "./src/index.tsx",
  12. resolve: {
  13. extensions: [".js", ".jsx", ".ts", ".tsx"],
  14. },
  15. output: {
  16. path: resolve(__dirname, "dist"),
  17. },
  18. module: {
  19. rules: [
  20. {
  21. test: /\.mjs$/,
  22. include: /node_modules/,
  23. type: "javascript/auto",
  24. resolve: {
  25. fullySpecified: false,
  26. },
  27. },
  28. {
  29. test: [/\.jsx?$/, /\.tsx?$/],
  30. use: ["ts-loader"],
  31. exclude: /node_modules/,
  32. },
  33. {
  34. test: /\.css$/,
  35. use: ["style-loader", "css-loader"],
  36. },
  37. {
  38. test: /\.(scss|sass)$/,
  39. use: ["style-loader", "css-loader", "postcss-loader"],
  40. },
  41. {
  42. test: /\.(jpe?g|png|gif|svg)$/i,
  43. use: [
  44. "file-loader?hash=sha512&digest=hex&name=img/[contenthash].[ext]",
  45. "image-webpack-loader?bypassOnDebug&optipng.optimizationLevel=7&gifsicle.interlaced=false",
  46. ],
  47. },
  48. {
  49. test: /\.(woff|woff2|ttf)$/,
  50. use: {
  51. loader: "url-loader",
  52. },
  53. },
  54. ],
  55. },
  56. plugins: [
  57. new CopyPlugin({
  58. patterns: [
  59. {
  60. from: "node_modules/onnxruntime-web/dist/*.wasm",
  61. to: "[name][ext]",
  62. },
  63. {
  64. from: "model",
  65. to: "model",
  66. },
  67. {
  68. from: "src/assets",
  69. to: "assets",
  70. },
  71. ],
  72. }),
  73. new HtmlWebpackPlugin({
  74. template: "./src/assets/index.html",
  75. }),
  76. new FriendlyErrorsWebpackPlugin(),
  77. new webpack.ProvidePlugin({
  78. process: "process/browser",
  79. }),
  80. ],
  81. };