-
Notifications
You must be signed in to change notification settings - Fork 13
Possible to use namespaces in browser? #13
Comments
It's not possible to use any of the filesystem loaders in the browser. But I wonder why storybookjs is using the browser flavor of Twing? Do you have a project that you can share that I can have a look at? |
Sure! Here's a stripped down version of what I'm using: https://github.com/robertromore/twing-storybook-example. |
Hi, any news here. Got the same problem. |
I dig through the code to find out how to implement for namespaces browser support. For Twig.js there is a loader which is doing that by requiring all included files in the Webpack Loader and replaces the includes with the associated id. See here: (https://github.com/AmazeeLabs/twig-loader/blob/master/lib/compiler.js). Which is working quit well. @ericmorand Maybe you can give me a hint how would you implement that in Twing. I think I need an TwingLoader and I need some kind of logic inside the webpack loader which writes the the included files into a map so the TwingLoader can read from that map? |
I think this might be the key. Since we are all using the BTW, I'm using the updated |
@christianwiedemann @JohnAlbin (hi Drupal friends!) - did you find a solution or workaround for this? |
With a custom environment.js file, you can switch the loader behaviour dynamically. When it's on the node/webpack side, it does all the // file: environment.js
const isNode = typeof process !== 'undefined'
&& process.versions != null
&& process.versions.node != null;
if (isNode) {
twingLoader = new TwingLoaderFilesystem();
// Do stuff.
}
else {
// Noop implementation for Browsers.
twingLoader = new TwingLoaderArray([]);
}
// Rest of the code. Examples of other implementations with twing-loader + storybook:
|
I assume it comes from the "browser" entry of Twing's package.json:
Which should not be used by Storybook, since it is compiling and rendering the templates from a Node environment and not from a browser one. There is something that I don't quite understand with Storybook. |
@ericmorand No Storybook renders "stories" always in the browser. |
@codebymikey Could you share a more complete code fragment? What is "it" and how it "has references to the files loaded from the filesystem"? |
Hi, I realized right now that namespaces are already supprted. Here a sample environment.js
The loader replaces TwingLoaderFilesystem with a prefilled PathArrayLoader. That's the reason for the |
Hi! I am trying to use twing-loader with storybookjs which is loading the browser version of Twing. I am trying to use the TwingSystemFilesystem loader to load my files in my environment file, but the browser version of Twing is returning TwingLoaderNull. The TwingSystemFilesystem class supports adding namespaces, but the TwingLoaderNull class doesn't.
I'm thinking the solution lies in this package, as this package is loading the files and parsing the
include
andextends
functions.Is there a way to do this currently?
The text was updated successfully, but these errors were encountered: