react-lazy-ssr icon indicating copy to clipboard operation
react-lazy-ssr copied to clipboard

CSS is included in reactLazySsrStats.json

Open revskill10 opened this issue 4 years ago • 1 comments

I'm using Razzle, and i got css included in reactLazySsrStats.json

{
  "publicPath": "/",
  "chunks": {
    "client": [
      "static/css/bundle.9823d995.css",
      "static/js/bundle.b6483aa5.js",
      "static/js/bundle.b6483aa5.js.map"
    ],
    "src-components-tinymce": [
      "static/js/vendors~src-components-tinymce.44d0aba7.chunk.js",
      "static/js/vendors~src-components-tinymce.44d0aba7.chunk.js.map",
      "static/js/src-components-tinymce.e63dcbc5.chunk.js",
      "static/js/src-components-tinymce.e63dcbc5.chunk.js.map"
    ]
  }
}

It causes error

Uncaught SyntaxError: Unexpected token '<'

because it's rendered as <script> javascript tag.

How to fix this ?

revskill10 avatar May 19 '20 22:05 revskill10

What @revskill10 say is correct... But the problem is not that its adding the CSS files, from my understanding the problem is in chunkExtractor.getScriptTags() which considers everything under that array is a js file and its not.

I've built myself a filter function on top of what we have now to filter those.. If u have not fixed it yet u may take a look:

  const { _chunkFiles, _entryPoints: [entryPoint] } = chunkExtractor;
  const polyfills = _chunkFiles.polyfills.filter((file) => !/\.map$/gi.test(file))
  const entryPointFiles = _chunkFiles[entryPoint].filter((file) => !/\.map$/gi.test(file))
  const cssEntryPointFiles =  _chunkFiles[entryPoint].filter((file) => !/\.css$/gi.test(file))
  const jsEntryPointFiles =  _chunkFiles[entryPoint].filter((file) => !/\.css$/gi.test(file))

elribonazo avatar Jun 24 '20 16:06 elribonazo