Skip to content

Commit

Permalink
C3: handle new next.config.mjs default files
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Jan 30, 2024
1 parent 1cb2783 commit 522f749
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 19 deletions.
8 changes: 8 additions & 0 deletions .changeset/forty-boxes-lay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"create-cloudflare": patch
---

handle new Next.js `next.config.mjs` default files

Since `create-next-app` `v14.1.0` the default generated config file is `next.config.mjs`
(instead of `next.config.js`), so such new default files need to be handled accordingly
2 changes: 1 addition & 1 deletion packages/create-cloudflare/templates/next/c3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ const configure = async (ctx: C3Context) => {
await writeEslintrc(ctx);
}

writeFile(`${projectPath}/next.config.js`, nextConfig);
writeFile(`${projectPath}/next.config.mjs`, nextConfig);
updateStatus("Updated the next.config.js file");

writeFile(`${projectPath}/README.md`, readme);
Expand Down
36 changes: 18 additions & 18 deletions packages/create-cloudflare/templates/next/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,30 +180,30 @@ const styles = {
} as const;
`;

export const nextConfig = `/** @type {import('next').NextConfig} */
const nextConfig = {}
export const nextConfig = `import { setupDevBindings } from '@cloudflare/next-on-pages/next-dev';
module.exports = nextConfig
/** @type {import('next').NextConfig} */
const nextConfig = {};
// Here we use the @cloudflare/next-on-pages next-dev module to allow us to use bindings during local development
// (when running the application with \`next dev\`), for more information see:
// https://github.com/dario-piotrowicz/next-on-pages/blob/8e93067/internal-packages/next-dev/README.md
// https://github.com/cloudflare/next-on-pages/blob/8e93067/internal-packages/next-dev/README.md
if (process.env.NODE_ENV === 'development') {
import('@cloudflare/next-on-pages/next-dev').then(({ setupDevBindings }) => {
setupDevBindings({
bindings: {
// Add here the Cloudflare Bindings you want to have available during local development,
// for more details on Bindings see: https://developers.cloudflare.com/pages/functions/bindings/)
//
// KV Example:
// MY_KV: {
// type: 'kv',
// id: 'xxx',
// }
}
})
})
await setupDevBindings({
bindings: {
// Add here the Cloudflare Bindings you want to have available during local development,
// for more details on Bindings see: https://developers.cloudflare.com/pages/functions/bindings/)
//
// KV Example:
// MY_KV: {
// type: 'kv',
// id: 'xxx',
// }
}
});
}
export default nextConfig;
`;

export const envDts = `declare global {
Expand Down

0 comments on commit 522f749

Please sign in to comment.