github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/scripts/webpack/webpack.lib.ts (about)

     1  import path from 'path';
     2  import MiniCssExtractPlugin from 'mini-css-extract-plugin';
     3  import { ESBuildMinifyPlugin } from 'esbuild-loader';
     4  import CopyWebpackPlugin from 'copy-webpack-plugin';
     5  import { getAlias, getJsLoader, getStyleLoaders } from './shared';
     6  
     7  const common = {
     8    mode: 'production',
     9    devtool: 'source-map',
    10  
    11    resolve: {
    12      extensions: ['.ts', '.tsx', '.es6', '.js', '.jsx', '.json', '.svg'],
    13      alias: getAlias(),
    14      modules: [
    15        'node_modules',
    16        path.resolve('webapp'),
    17        path.resolve('node_modules'),
    18      ],
    19    },
    20  
    21    watchOptions: {
    22      ignored: /node_modules/,
    23    },
    24  
    25    optimization: {
    26      minimizer: [
    27        new ESBuildMinifyPlugin({
    28          target: 'es2015',
    29          css: true,
    30        }),
    31      ],
    32    },
    33  
    34    module: {
    35      // Note: order is bottom-to-top and/or right-to-left
    36      rules: [
    37        ...getJsLoader(),
    38        ...getStyleLoaders(),
    39        {
    40          test: /\.svg$/,
    41          use: [
    42            { loader: 'babel-loader' },
    43            {
    44              loader: 'react-svg-loader',
    45              options: {
    46                svgo: {
    47                  plugins: [
    48                    { convertPathData: { noSpaceAfterFlags: false } },
    49                    { removeViewBox: false },
    50                  ],
    51                },
    52              },
    53            },
    54          ],
    55        },
    56      ],
    57    },
    58  
    59    plugins: [
    60      new MiniCssExtractPlugin({}),
    61      new CopyWebpackPlugin({
    62        patterns: [
    63          { from: path.join('./packages/flamegraph/', 'README.md'), to: '.' },
    64          {
    65            from: path.join('./packages/flamegraph/', 'package.json'),
    66            to: '.',
    67          },
    68        ],
    69      }),
    70      //   new ReplaceInFileWebpackPlugin([
    71      //     {
    72      //       dir: './dist/lib',
    73      //       files: ['package.json', 'README.md'],
    74      //       rules: [
    75      //         {
    76      //           search: '%VERSION%',
    77      //           replace: version,
    78      //         },
    79      //         {
    80      //           search: '%TODAY%',
    81      //           replace: new Date().toISOString().substring(0, 10),
    82      //         },
    83      //       ],
    84      //     },
    85      //   ]),
    86    ],
    87  };
    88  
    89  export default [
    90    {
    91      ...common,
    92      target: 'node',
    93      mode: 'production',
    94      devtool: 'source-map',
    95      entry: {
    96        index: './packages/flamegraph/src/index.node.ts',
    97      },
    98      output: {
    99        publicPath: '',
   100        path: path.resolve(__dirname, '../../packages/flamegraph/dist'),
   101        libraryTarget: 'commonjs',
   102        filename: 'index.node.js',
   103      },
   104    },
   105    {
   106      ...common,
   107      target: 'web',
   108      mode: 'production',
   109      devtool: 'source-map',
   110      entry: {
   111        index: './packages/flamegraph/src/index.tsx',
   112      },
   113      output: {
   114        publicPath: '',
   115        path: path.resolve(__dirname, '../../packages/flamegraph/dist'),
   116        libraryTarget: 'umd',
   117        library: 'pyroscope',
   118        filename: 'index.js',
   119        globalObject: 'this',
   120      },
   121  
   122      externals: {
   123        react: 'react',
   124        reactDom: 'react-dom',
   125      },
   126    },
   127  ];