Distributing a next.js app via NPM #11606
Replies: 4 comments 9 replies
-
|
I've got the demo project working now! It looks like the webpack rule that next uses explicitly ignores all files within // from next.config.js
module.exports = {
webpack: (config) => {
const rule = config.module.rules[0];
const originalExcludeMethod = rule.exclude;
config.module.rules[0].exclude = (moduleName, ...otherArgs) => {
// we want to explicitly allow our plugin
if (moduleName.indexOf("node_modules/next-subproject-example") >= 0) {
return false;
}
// otherwise, use the original rule
return originalExcludeMethod(moduleName, ...otherArgs);
};
return config;
},
}; |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your solution. Great! I've similar situation: i have a core next js project( that is shipped as an npm package, like you said). But i have problem with weback, receiving this error: Could you provide some help? |
Beta Was this translation helpful? Give feedback.
-
|
I need some help on the same. I'm trying to build an app on next-js where i'm using SSR components. I want to build an npm package out of it which I can use in my old react project. |
Beta Was this translation helpful? Give feedback.
-
|
Is there any way to make it work with TurboPack? Currently, I am copying the node_modules/next-project folder into a temporary folder, which works with npm but not with pnpm due to the stricter package structure. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
(related to and coppied from #11411)
Hello!
We are looking at distributing our next.js application via NPM, but are having trouble getting webpack to work properly when running next from /within/
node_modules. We want to allow folks to runnext devandnext buildin our project so they can add plugins and modify behavior - meaning we can't runnext buildand ship that ourselves. Our users would install peerDependencies which would be bundled into the next application.The goal is to have something like this:
I've published
next-subproject-example(github) to npm which is a very simple next.js application with one page and no custom config.package.json, which aims to consumenext-subproject-example{ "name": "my-project", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "cd node_modules/next-subproject-example && npm run dev", "build": "cd node_modules/next-subproject-example && npm run prepare" }, "dependencies": { "next-subproject-example": "latest" }, "license": "ISC", "devDependencies": { "@types/node": "^13.9.5", "@types/react": "^16.9.26" } }npm installnpm run devBeta Was this translation helpful? Give feedback.
All reactions