---
title: "Use a bundler"
slug: "use-a-bundler"
abstract: "Example of how to use a bundler to compile TypeScript code for use with an external page component."
---
# Use a bundler

You can use a bundler, such as [webpack](https://webpack.js.org/guides/ecma-script-modules/) or vite, to compile TypeScript code and make a bundle. If you do this, ensure the target is` ["web", "es2020"]` as shown in the following example of a webpack `config` file.

> [!note]
> If you based your code on any of the [TypeScript examples](https://doc.sitecore.com/ch/en/users/content-hub/examples.html "Examples") provided, make sure that the TypeScript is compiled to JavaScript.

> [!tip]
> The [Sitecore Content Hub - External Components](https://www.youtube.com/watch?v=nIjaOUrv-Xs) video available on the Discover Sitecore channel covers using a bundler.

```typescript
const path = require("path");
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin");
const webpack = require("webpack");

module.exports = {
    entry: "./index.tsx",
    target: ["web", "es2020"],
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: "ts-loader",
                exclude: /node_modules/,
            },
        ],
    },
    resolve: {
        extensions: [".tsx", ".ts", ".js"],
        fallback: {
            fs: false,
            https: false,
        },
    },
    devtool: "source-map",
    output: {
        filename: "bundle.js",
        path: path.resolve(__dirname, "dist"),
        library: {
            type: "module",
        },
    },
    experiments: { outputModule: true, backCompat: false },
    devServer: {
        static: path.join(__dirname, "dist"),
        compress: true,
        port: 4000,
    },
    optimization: {
        minimize: false,
    },
    plugins: [
        new NodePolyfillPlugin(),
        new webpack.ProvidePlugin({
            process: "process/browser",
        }),
    ],
};

```