Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buildless option #270

Open
lukexor opened this issue Nov 22, 2023 · 4 comments
Open

Buildless option #270

lukexor opened this issue Nov 22, 2023 · 4 comments

Comments

@lukexor
Copy link

lukexor commented Nov 22, 2023

SolidJS supports buildless templating: https://www.solidjs.com/guides/getting-started#buildless-options

which I was experimenting with using jsdelivr - however, while jsdelivr does have @suid/material hosted because there's an npm package - it doesn't seem usable in its current jsx packaged state. I've tried skypack and unpkg as well with the same issue.

Here's a comparison with @mui/material:

https://cdn.jsdelivr.net/npm/@mui/material@5.14.18 - application/javascript; charset=utf-8
and for esm: https://cdn.jsdelivr.net/npm/@mui/material@5.14.18/+esm
https://cdn.jsdelivr.net/npm/@suid/material@0.15.1 - text/jsx; charset=utf-8

Attempting to use @suid/material results in:

The resource from “https://cdn.jsdelivr.net/npm/@suid/material@0.15.1” was blocked due to MIME type (“text/jsx”) mismatch (X-Content-Type-Options: nosniff).

I also experimented with trying to use @babel/standalone but didn't have any success.

I'd love to be able to deploy buildless widgets using Solid and SUID.

@lukexor
Copy link
Author

lukexor commented Nov 22, 2023

also for reference: solidjs/solid#1159

@lukexor
Copy link
Author

lukexor commented Nov 22, 2023

I did find that esm.sh has a pre-compiled version of @suid/material as well but they're using the default esbuild settings and so it inserts React.createComponent transpiled code.

I was then able to get this working by building an esm version of @suid/material locally.

If this could be added to the npm release in such a way that esm.sh or jsdelivr can provide it correctly as an esm module, that would be great. Otherwise I'll just have to build and host it locally.

const { build } = require("esbuild");
const { solidPlugin } = require("esbuild-plugin-solid");

build({
  entryPoints: ["lib/index.jsx"],
  bundle: true,
  format: "esm",
  outfile: "dist/index.js",
  // minify: true,
  loader: {
    ".svg": "dataurl",
  },
  logLevel: "info",
  plugins: [solidPlugin()],
}).catch(() => process.exit(1));

@lukexor
Copy link
Author

lukexor commented Nov 27, 2023

The build option above doesn't quite work though because of how refs are handled in non-compiled environments requiring that refs are always in callback form: https://github.com/solidjs/solid/tree/main/packages/solid/html

And even if I try to modify some components to ensure the callback form is being used, it ends up failing with undefined refs. Somehow the onMount and createEffect callbacks are being called before the ref is ever being triggered by createComponent. I haven't been able to figure out why yet - but have confirmed that setting ref on native DOM nodes and other components like Button seem to work fine with solid as-is from https://esm.sh/solid-js@1.8.5 which indicates something inherently incompatible with @Suid for use within build-less html unless I'm missing something

@lukexor
Copy link
Author

lukexor commented Nov 29, 2023

I was able to get a static buildless example working with the following changes:

A vite.config.ts file to packages/material:

import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";

export default defineConfig({
  plugins: [solidPlugin()],
  define: { "process.env.NODE_ENV": '"production"' },
  build: {
    target: "esnext",
    rollupOptions: {
      external: ["solid-js"],
    },
    lib: {
      entry: "src/index.tsx",
      formats: ["es"],
    },
  },
});

Adding "type": "module" to packages/material/package.json and then building with vite build then serving up packages/material/dist/material.js via a CDN

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant