Replies: 3 comments 10 replies
-
Hi, I'm working on a similar subject. My goal is to build widgets at the same time I build my nextJS website. I think this feature is a step to get something like micro-frontend using nextJS.... I saw another question on the same topic here but I thing your question is expressed more clearly so I suggest to continue here for this subject. On my side, I managed to trigger a second webpack build during nextJS build with a config modified so the entry point is the script for my widget, and chunk splitting is done a different way to be compatible with a widget usage (webpack runtime included). If you have made some progress on this subject since you posted your message, please share any idea ;) I think the best solution to get this done would be to add some entries in the webpack config. But these entries should not be built exactly the same as others: webpack runtime should be included, chunks splitting should probably be a little different... I hope we can manage to get a solution soon |
Beta Was this translation helpful? Give feedback.
-
This answer was provided by Jesper We on StackOverflow: The loaded script would have to create the Next creates a full page, not an object that can be called as described above. To change this we'd need to override the Next server to bypass the whole |
Beta Was this translation helpful? Give feedback.
-
Hi there, I finally found some time to build something. The idea : Add a webpack plugin that will catch "beforeRun" hook in the NextJS build process and start a second webpack build that will build widgets into the /_next/static/widgets/.... folder The second webpack build is created using the initial webpack config, so we inherit all NextJS webpack config. Just a few changes and we have a full webpack config to build widgets. I'm sure this will not match everyone's cases.... but for me it works really well. With the same codebase, one build process and I get both a working NextJS website AND ready to load widgets. For the widget code I used custom-elements so they are really easy to use: just load a JS file and add custom HTML tags wherever you like. I'd love to have feedback on that, good or bad I don't care, as long as it can help find improvements ;) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm attempting to create widgets for our customers to paste (embed) within their own site.
Ideally to be used by a third-party like so:
example.html
I just can't figure out how to "bundle" specific entry points down to a single file with next.js.
I'm using Vercel which builds from GitHub, so ideally I want these bundles to be generated on build, without breaking the existing next.js site.
What I've tried:
next.config.js
Result:
This achieves nothing, and I don't understand why! :(
Useful Sources:
Github (Next.js Discussions): Adding a Webpack entry to load separately from main.js
Next.js: Custom Webpack Config
Next.js: Setting a custom build directory
Next.js: exportPathMap
Stackoverflow: Writing embeddable Javascript plugin with React & Webpack
Webpack: Configuration Documentation
Beta Was this translation helpful? Give feedback.
All reactions