GoogleChromeLabs / webbundle-plugins

A Webpack plugin for generating Web Bundles output.
https://www.npmjs.com/package/webbundle-webpack-plugin
Apache License 2.0
59 stars 11 forks source link

Trying to use Rollup version. What am I doing incorrectly? #67

Closed guest271314 closed 11 months ago

guest271314 commented 11 months ago

lib/index.js

index.js.zip

node --experimental-default-type=module rollup.config.js

rollup.config.js

import wbnOutputPlugin from "./lib/index.js";
import * as wbnSign from "wbn-sign";
import * as fs from "node:fs";
import * as path from "node:path";

const privateKeyFile = "ed25519key.pem";
const privateKey = fs.readFileSync(privateKeyFile);

const build = async () => {
  const key = wbnSign.parsePemKey(
    privateKey
  );

  return {
    input: "./src/index.js",
    output: { dir: "dist", format: "esm" },
    plugins: [
      wbnOutputPlugin({
        baseURL: new wbnSign.WebBundleId(
          key,
        ).serializeWithIsolatedWebAppOrigin(),
        static: { dir: "assets" },
        output: "signed.swbn",
        integrityBlockSign: {
          strategy: new wbnSign.NodeCryptoSigningStrategy(key),
        },
        headerOverride: {
          "cross-origin-embedder-policy": "require-corp",
          "cross-origin-opener-policy": "same-origin",
          "cross-origin-resource-policy": "same-origin",
          "content-security-policy":
            "base-uri 'none'; default-src 'self'; object-src 'none'; frame-src 'self' https: blob: data:; connect-src 'self' https: wss:; script-src 'self' 'wasm-unsafe-eval'; img-src 'self' https: blob: data:; media-src 'self' https: blob: data:; font-src 'self' blob: data:; style-src 'self' 'unsafe-inline'; require-trusted-types-for 'script';",
        },
      }),
    ],
  };
};

build().then((o) => {
const {plugins:[{generateBundle}]} = o;
console.log({ o });
return generateBundle()  })
.then(console.log).catch(console.error);
guest271314 commented 11 months ago

I figured it out reading test.js

const bundle = await rollup.rollup({ input: "src/script.js",...});
const { output } = await bundle.generate({ format: 'esm' });
const [{ fileName, source }] = output;
fs.writeFileSync(fileName, source);