How to serve static content from node modules #12844
-
|
First off, I'd like to say that I'm new to Next.js now, but have been loving it so far. Right now I'm having trouble integrating with Cesium. I started off with the default next.js template. Then I started editing the next.config.js file to include the same configs from the Cesium webpack example here: https://github.com/CesiumGS/cesium-webpack-example/blob/master/webpack.config.js I'm having trouble having access to the static files though. Every request to Workers/Assets/Widgets, etc. gets a 404, which I assume is a side effect of next.js being opinionated and is probably intended behavior. I saw the next.js documentation on static file serving, but it only explains how to serve a single file at a time. I'm curious if anyone has any ideas on how I could serve an entire directory from node modules via the public directory (or any other directory). This is what my current next.config.js looks like: I have also tried getting around it by making the cesium base url public and copying them there instead, but I had no luck there. Does anyone have any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
|
I was able to get this working by pre-pending "../public" to each of the "to" arguments in the copy webpack plugins. e.g. |
Beta Was this translation helpful? Give feedback.
-
|
This isn't a great solution because it requires me to add directories within |
Beta Was this translation helpful? Give feedback.
-
|
I also have this question, as I have a service worker file in a node module that I need to serve somehow. Did you find any better way? |
Beta Was this translation helpful? Give feedback.
-
|
It seems that copying to static/ is a good option. |
Beta Was this translation helpful? Give feedback.
-
|
FYI I have resorted to using an inline webpack import: import cssInjectableUrl from '!file-loader?{"publicPath":"/_next/static","outputPath":"static"}!extract-loader!css-loader!@nypl/web-reader/dist/injectable-html-styles.css';This copies it to my public directory and gives me the url to it |
Beta Was this translation helpful? Give feedback.
-
|
I think you're missing The following code syntax worked for me: |
Beta Was this translation helpful? Give feedback.
I was able to get this working by pre-pending "../public" to each of the "to" arguments in the copy webpack plugins. e.g.
to: "../public/Workers". I suppose this makes sense because the build directory is.next, but this seems like a strange convention to me. Is there a cleaner way to accomplish this?