You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
please add support for isomorphic-loader for module type projects (and hybrid variants).
We are currently facing two issues here:
(1) extendRequire does not work for ES modules. I played around writing our own ESM loader (only works on Node >=16.12):
importfsfrom'fs'importpathfrom'path'importassertfrom'assert'constisomorphicLoaderConfig=JSON.parse(awaitfs.promises.readFile(path.join(process.cwd(),'.isomorphic-loader-config.json'),'utf-8'))assert.ok(isomorphicLoaderConfig?.assetsFile,'please run "yarn build:staticResources" before running "yarn build:staticPages"')constisomorphicAssets=JSON.parse(awaitfs.promises.readFile(isomorphicLoaderConfig.assetsFile,'utf-8'))constEXTENSIONS=['.svg','.jpg','.png']exportasyncfunctionresolve(specifier,context,defaultResolve){const{ parentURL =null}=contextif(EXTENSIONS.some((ext)=>specifier.endsWith(ext))){consturl=parentURL ? newURL(specifier,parentURL).href : newURL(specifier).hrefreturn{ url }}returndefaultResolve(specifier,context)}exportasyncfunctionload(url,context,defaultLoad){if(EXTENSIONS.some((ext)=>url.endsWith(ext))){constassetPath=Object.keys(isomorphicAssets.marked).find((asset)=>url.endsWith(asset))if(assetPath){return{format: 'json',source: `"/our-prefix/${isomorphicAssets.marked[assetPath]}"`,}}thrownewError(`Did not find asset ${url} in isomorphic-assets.json`)}returndefaultLoad(url,context,defaultLoad)}
A hybrid solution would mean to also support CJS dependencies which still use require.
(2) Maybe webpack 4 or TypeScript related, but the isomorphic-assets.json is missing the entries in marked that are direct dependencies of es module files. I checked the webpack-plugin.js and the top level modules list traversed by this snippet is not containing the relevant modules. Instead they can be found in nested modules:
Hi,
please add support for isomorphic-loader for
module
type projects (and hybrid variants).We are currently facing two issues here:
(1)
extendRequire
does not work for ES modules. I played around writing our own ESM loader (only works on Node >=16.12):A hybrid solution would mean to also support CJS dependencies which still use
require
.(2) Maybe webpack 4 or TypeScript related, but the
isomorphic-assets.json
is missing the entries inmarked
that are direct dependencies of es module files. I checked thewebpack-plugin.js
and the top level modules list traversed by this snippet is not containing the relevant modules. Instead they can be found in nested modules:I do not know enough of the internals of webpack to propose a fix here - maybe it's already a bug in the
ts-loader
orfile-loader
...The text was updated successfully, but these errors were encountered: