123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- const path = require("path");
- const TerserPlugin = require("terser-webpack-plugin");
- const BundleAnalyzerPlugin =
- require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
- const autoprefixer = require("autoprefixer");
- const webpack = require("webpack");
- const { parseEnvVariables } = require("./env");
- module.exports = {
- mode: "production",
- entry: {
- "excalidraw.production.min": "./entry.js",
- },
- output: {
- path: path.resolve(__dirname, "dist"),
- library: "Excalidraw",
- libraryTarget: "umd",
- filename: "[name].js",
- chunkFilename: "excalidraw-assets/[name]-[contenthash].js",
- publicPath: "",
- },
- resolve: {
- extensions: [".js", ".ts", ".tsx", ".css", ".scss"],
- },
- module: {
- rules: [
- {
- test: /\.(sa|sc|c)ss$/,
- exclude: /node_modules/,
- use: [
- "style-loader",
- {
- loader: "css-loader",
- },
- {
- loader: "postcss-loader",
- options: {
- postcssOptions: {
- plugins: [autoprefixer()],
- },
- },
- },
- "sass-loader",
- ],
- },
- {
- test: /\.(ts|tsx|js|jsx|mjs)$/,
- exclude: /node_modules/,
- use: [
- {
- loader: "ts-loader",
- options: {
- transpileOnly: true,
- configFile: path.resolve(__dirname, "../tsconfig.prod.json"),
- },
- },
- {
- loader: "babel-loader",
- options: {
- presets: [
- "@babel/preset-env",
- ["@babel/preset-react", { runtime: "automatic" }],
- "@babel/preset-typescript",
- ],
- plugins: [
- "@babel/plugin-proposal-object-rest-spread",
- "@babel/plugin-transform-arrow-functions",
- "transform-class-properties",
- "@babel/plugin-transform-async-to-generator",
- "@babel/plugin-transform-runtime",
- ],
- },
- },
- ],
- },
- {
- test: /\.(woff|woff2|eot|ttf|otf)$/,
- use: [
- {
- loader: "file-loader",
- options: {
- name: "[name].[ext]",
- outputPath: "excalidraw-assets",
- },
- },
- ],
- },
- ],
- },
- optimization: {
- minimize: true,
- minimizer: [
- new TerserPlugin({
- test: /\.js($|\?)/i,
- }),
- ],
- splitChunks: {
- chunks: "async",
- cacheGroups: {
- vendors: {
- test: /[\\/]node_modules[\\/]/,
- name: "vendor",
- },
- },
- },
- },
- plugins: [
- ...(process.env.ANALYZER === "true" ? [new BundleAnalyzerPlugin()] : []),
- new webpack.DefinePlugin({
- "process.env": parseEnvVariables(
- path.resolve(__dirname, "../../../.env.production"),
- ),
- }),
- ],
- externals: {
- react: {
- root: "React",
- commonjs2: "react",
- commonjs: "react",
- amd: "react",
- },
- "react-dom": {
- root: "ReactDOM",
- commonjs2: "react-dom",
- commonjs: "react-dom",
- amd: "react-dom",
- },
- },
- };
|