playroom icon indicating copy to clipboard operation
playroom copied to clipboard

Custom fonts/static assets

Open mxkxf opened this issue 3 years ago • 4 comments

Hey there,

Thanks for making Playroom.

I'd like to serve up some local fonts to use from within Playroom but can't find any docs on how to do this.

Is it possible?

mxkxf avatar Jan 24 '22 15:01 mxkxf

Hey 👋

I would recommend doing this with a custom FrameComponent.

Here is a basic example:

// FrameComponent.tsx

export default ({ children }) => {
  return (
    <>
      <link href="---web font url---" rel="stylesheet" />
      {children}
    </>
  );
}

And then provide the path of that file to your playroom config:

// playroom.config.js

module.exports = {
  // ...
  frameComponent: './FrameComponent.tsx'
}

michaeltaranto avatar Jan 24 '22 23:01 michaeltaranto

@michaeltaranto Thanks for the reply! Is there any way to host the fonts from the playroom dev server without these being served from the public web?

mxkxf avatar Jan 25 '22 08:01 mxkxf

I've been trying to use a custom frame component to remove the margin on the iframe

element body tag, etc

I did exactly what you suggest above (copy and paste), and i've been getting:

image

my Frame.tsx is:

export default ({ children }) => {
  return (
    <>
      <link href="---web font url---" rel="stylesheet" />
      {children}
    </>
  );
}

michaelwarren1106 avatar Feb 02 '22 22:02 michaelwarren1106

@michaelwarren1106 You'll need to add a CSS loader to your webpack config:

// playroom.config.js

module.exports = {
  // ...
  webpackConfig: () => ({
    module: {
      rules: [
        {
          test: /\.css$/,
          exclude: /node_modules/,
          use: ['style-loader', 'css-loader'],
        },
      ],
    },
  },
  // ...
};

mxkxf avatar Feb 10 '22 08:02 mxkxf