Closed4

Rspackでバンドルを行う

3w36zj63w36zj6

依存関係の追加

bun init
bun install --dev @rspack/cli

設定

エントリーポイントをsrc/index.ts、出力先をdist/bundle.jsとする。

tsconfig.json
@@ -18,5 +18,6 @@
     "types": [
       "bun-types" // add Bun global
     ]
-  }
+  },
+  "include": ["src/**/*"]
 }
rspack.config.js
// @ts-check

const isProduction = process.env.NODE_ENV === "production"

/** @type {import('@rspack/cli').Configuration} */
const config = {
  entry: "./src/index.ts",
  output: {
    filename: "bundle.js",
    path: "./dist/",
  },
  module: {
    rules: [
      {
        test: /\.ts$/,
        use: "builtin:swc-loader",
      },
    ],
  },
  devServer: { static: { directory: "./dist/" } },
  devtool: isProduction ? false : "source-map", // Production BuildのときにSource mapsを含めない
}

module.exports = config

ビルド

bun run rspack build --mode production

開発サーバー

bun run rspack serve
このスクラップは5ヶ月前にクローズされました