hupe1980 / gatsby-plugin-webfonts

A Gatsby plugin to handle cdn, base64 and self hosted webfonts
MIT License
55 stars 0 forks source link

Implement Gatsby v3 support #17

Closed daugsbi closed 3 years ago

daugsbi commented 3 years ago

First of all, thanks for this gatsby plugin :+1:

I was curious and tried out the new Gatsby version 3. There is now a restriction on using fs and path, which should be imported from the bundler. Checkout https://www.gatsbyjs.com/docs/reference/release-notes/migrating-from-v2-to-v3/#using-fs-in-ssr

Currently a warning is thrown at build time regarding this issue

warn WebpackError: Unsafe builtin usage fs.readFileSync
    at gatsby-starter-default/node_modules/gatsby-plugin-webfonts/gatsby-ssr.js:37:25
    at gatsby-starter-default/.cache/api-runner-ssr.js:69:22
    at gatsby-starter-default/.cache/api-runner-ssr.js:64:17
    at gatsby-starter-default/.cache/static-entry.js:270:5
    at gatsby-starter-default/node_modules/@babel/runtime/helpers/esm/inheritsLoose.js:3:1

  35 |       options = (0, _objectWithoutPropertiesLoose2.default)(_createOptions, ["usePreload", "formats"]);
  36 |
> 37 |   var css = _fs.default.readFileSync(_path.default.join("./.cache", "webfonts", "webfonts.css"), "utf8");
     |                         ^
  38 |
  39 |   setHeadComponents([/*#__PURE__*/_react.default.createElement(_preconnect.default, {
  40 |     key: "webFontsPreconnectGoogleFonts",
hupe1980 commented 3 years ago

closed with #18