diff --git a/examples/next-13/.gitignore b/examples/next-13/.gitignore new file mode 100644 index 0000000..8f322f0 --- /dev/null +++ b/examples/next-13/.gitignore @@ -0,0 +1,35 @@ +# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. + +# dependencies +/node_modules +/.pnp +.pnp.js + +# testing +/coverage + +# next.js +/.next/ +/out/ + +# production +/build + +# misc +.DS_Store +*.pem + +# debug +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# local env files +.env*.local + +# vercel +.vercel + +# typescript +*.tsbuildinfo +next-env.d.ts diff --git a/examples/next-13/README.md b/examples/next-13/README.md new file mode 100644 index 0000000..c403366 --- /dev/null +++ b/examples/next-13/README.md @@ -0,0 +1,36 @@ +This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). + +## Getting Started + +First, run the development server: + +```bash +npm run dev +# or +yarn dev +# or +pnpm dev +# or +bun dev +``` + +Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. + +You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. + +This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. + +## Learn More + +To learn more about Next.js, take a look at the following resources: + +- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. +- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. + +You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! + +## Deploy on Vercel + +The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. + +Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. diff --git a/examples/next-13/app/+public/sw.ts b/examples/next-13/app/+public/sw.ts new file mode 100644 index 0000000..e2747f5 --- /dev/null +++ b/examples/next-13/app/+public/sw.ts @@ -0,0 +1,15 @@ +/// +export type {}; +declare let self: ServiceWorkerGlobalScope; + +self.addEventListener("install", async () => { + console.log("Service worker installed (cjs)"); +}); + +self.addEventListener("fetch", (evt: FetchEvent) => { + // Do your magic here. E.g. if you want to cache third party resources: +}); + +self.addEventListener("error", (err) => { + console.error("Service worker error", err); +}); diff --git a/examples/next-13/app/favicon.ico b/examples/next-13/app/favicon.ico new file mode 100644 index 0000000..718d6fe Binary files /dev/null and b/examples/next-13/app/favicon.ico differ diff --git a/examples/next-13/app/globals.css b/examples/next-13/app/globals.css new file mode 100644 index 0000000..fd81e88 --- /dev/null +++ b/examples/next-13/app/globals.css @@ -0,0 +1,27 @@ +@tailwind base; +@tailwind components; +@tailwind utilities; + +:root { + --foreground-rgb: 0, 0, 0; + --background-start-rgb: 214, 219, 220; + --background-end-rgb: 255, 255, 255; +} + +@media (prefers-color-scheme: dark) { + :root { + --foreground-rgb: 255, 255, 255; + --background-start-rgb: 0, 0, 0; + --background-end-rgb: 0, 0, 0; + } +} + +body { + color: rgb(var(--foreground-rgb)); + background: linear-gradient( + to bottom, + transparent, + rgb(var(--background-end-rgb)) + ) + rgb(var(--background-start-rgb)); +} diff --git a/examples/next-13/app/layout.tsx b/examples/next-13/app/layout.tsx new file mode 100644 index 0000000..40e027f --- /dev/null +++ b/examples/next-13/app/layout.tsx @@ -0,0 +1,22 @@ +import type { Metadata } from 'next' +import { Inter } from 'next/font/google' +import './globals.css' + +const inter = Inter({ subsets: ['latin'] }) + +export const metadata: Metadata = { + title: 'Create Next App', + description: 'Generated by create next app', +} + +export default function RootLayout({ + children, +}: { + children: React.ReactNode +}) { + return ( + + {children} + + ) +} diff --git a/examples/next-13/app/page.tsx b/examples/next-13/app/page.tsx new file mode 100644 index 0000000..7a8286b --- /dev/null +++ b/examples/next-13/app/page.tsx @@ -0,0 +1,113 @@ +import Image from 'next/image' + +export default function Home() { + return ( +
+
+

+ Get started by editing  + app/page.tsx +

+
+ + By{' '} + Vercel Logo + +
+
+ +
+ Next.js Logo +
+ +
+ +

+ Docs{' '} + + -> + +

+

+ Find in-depth information about Next.js features and API. +

+
+ + +

+ Learn{' '} + + -> + +

+

+ Learn about Next.js in an interactive course with quizzes! +

+
+ + +

+ Templates{' '} + + -> + +

+

+ Explore the Next.js 13 playground. +

+
+ + +

+ Deploy{' '} + + -> + +

+

+ Instantly deploy your Next.js site to a shareable URL with Vercel. +

+
+
+
+ ) +} diff --git a/examples/next-13/next.config.js b/examples/next-13/next.config.js new file mode 100644 index 0000000..d0e2976 --- /dev/null +++ b/examples/next-13/next.config.js @@ -0,0 +1,15 @@ +const { NextPublicTsPlugin } = require("next-public-ts"); +const path = require("node:path"); + +/** @type {import('next').NextConfig} */ +const nextConfig = { + webpack(config, context) { + config.plugins.push(new NextPublicTsPlugin({ + inputDir: path.join(__dirname, "src", "app", "+public"), + outputDir: path.join(__dirname, "public"), + })); + return config; + } +}; + +module.exports = nextConfig; diff --git a/examples/next-13/package.json b/examples/next-13/package.json new file mode 100644 index 0000000..82dc62b --- /dev/null +++ b/examples/next-13/package.json @@ -0,0 +1,26 @@ +{ + "name": "next-13", + "version": "0.1.0", + "private": true, + "scripts": { + "dev": "next dev", + "build": "next build", + "start": "next start", + "lint": "next lint" + }, + "dependencies": { + "next": "13.5.6", + "next-public-ts": "^0.0.4", + "react": "^18", + "react-dom": "^18" + }, + "devDependencies": { + "@types/node": "^20", + "@types/react": "^18", + "@types/react-dom": "^18", + "autoprefixer": "^10", + "postcss": "^8", + "tailwindcss": "^3", + "typescript": "^5" + } +} diff --git a/examples/next-13/postcss.config.js b/examples/next-13/postcss.config.js new file mode 100644 index 0000000..33ad091 --- /dev/null +++ b/examples/next-13/postcss.config.js @@ -0,0 +1,6 @@ +module.exports = { + plugins: { + tailwindcss: {}, + autoprefixer: {}, + }, +} diff --git a/examples/next-13/public/next.svg b/examples/next-13/public/next.svg new file mode 100644 index 0000000..5174b28 --- /dev/null +++ b/examples/next-13/public/next.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/next-13/public/vercel.svg b/examples/next-13/public/vercel.svg new file mode 100644 index 0000000..d2f8422 --- /dev/null +++ b/examples/next-13/public/vercel.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/next-13/tailwind.config.ts b/examples/next-13/tailwind.config.ts new file mode 100644 index 0000000..c7ead80 --- /dev/null +++ b/examples/next-13/tailwind.config.ts @@ -0,0 +1,20 @@ +import type { Config } from 'tailwindcss' + +const config: Config = { + content: [ + './pages/**/*.{js,ts,jsx,tsx,mdx}', + './components/**/*.{js,ts,jsx,tsx,mdx}', + './app/**/*.{js,ts,jsx,tsx,mdx}', + ], + theme: { + extend: { + backgroundImage: { + 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', + 'gradient-conic': + 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))', + }, + }, + }, + plugins: [], +} +export default config diff --git a/examples/next-13/tsconfig.json b/examples/next-13/tsconfig.json new file mode 100644 index 0000000..c714696 --- /dev/null +++ b/examples/next-13/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "target": "es5", + "lib": ["dom", "dom.iterable", "esnext"], + "allowJs": true, + "skipLibCheck": true, + "strict": true, + "noEmit": true, + "esModuleInterop": true, + "module": "esnext", + "moduleResolution": "bundler", + "resolveJsonModule": true, + "isolatedModules": true, + "jsx": "preserve", + "incremental": true, + "plugins": [ + { + "name": "next" + } + ], + "paths": { + "@/*": ["./*"] + } + }, + "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], + "exclude": ["node_modules"] +} diff --git a/package-lock.json b/package-lock.json index 6fb3cb2..70ac383 100644 --- a/package-lock.json +++ b/package-lock.json @@ -44,6 +44,209 @@ "typescript": "^5" } }, + "examples/next-13": { + "version": "0.1.0", + "dependencies": { + "next": "13.5.6", + "next-public-ts": "^0.0.4", + "react": "^18", + "react-dom": "^18" + }, + "devDependencies": { + "@types/node": "^20", + "@types/react": "^18", + "@types/react-dom": "^18", + "autoprefixer": "^10", + "postcss": "^8", + "tailwindcss": "^3", + "typescript": "^5" + } + }, + "examples/next-13/node_modules/@next/env": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/env/-/env-13.5.6.tgz", + "integrity": "sha512-Yac/bV5sBGkkEXmAX5FWPS9Mmo2rthrOPRQQNfycJPkjUAUclomCPH7QFVCDQ4Mp2k2K1SSM6m0zrxYrOwtFQw==" + }, + "examples/next-13/node_modules/@next/swc-darwin-arm64": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-13.5.6.tgz", + "integrity": "sha512-5nvXMzKtZfvcu4BhtV0KH1oGv4XEW+B+jOfmBdpFI3C7FrB/MfujRpWYSBBO64+qbW8pkZiSyQv9eiwnn5VIQA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "examples/next-13/node_modules/@next/swc-darwin-x64": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-13.5.6.tgz", + "integrity": "sha512-6cgBfxg98oOCSr4BckWjLLgiVwlL3vlLj8hXg2b+nDgm4bC/qVXXLfpLB9FHdoDu4057hzywbxKvmYGmi7yUzA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "examples/next-13/node_modules/@next/swc-linux-arm64-gnu": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-13.5.6.tgz", + "integrity": "sha512-txagBbj1e1w47YQjcKgSU4rRVQ7uF29YpnlHV5xuVUsgCUf2FmyfJ3CPjZUvpIeXCJAoMCFAoGnbtX86BK7+sg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "examples/next-13/node_modules/@next/swc-linux-arm64-musl": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-13.5.6.tgz", + "integrity": "sha512-cGd+H8amifT86ZldVJtAKDxUqeFyLWW+v2NlBULnLAdWsiuuN8TuhVBt8ZNpCqcAuoruoSWynvMWixTFcroq+Q==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "examples/next-13/node_modules/@next/swc-linux-x64-gnu": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-13.5.6.tgz", + "integrity": "sha512-Mc2b4xiIWKXIhBy2NBTwOxGD3nHLmq4keFk+d4/WL5fMsB8XdJRdtUlL87SqVCTSaf1BRuQQf1HvXZcy+rq3Nw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "examples/next-13/node_modules/@next/swc-linux-x64-musl": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-13.5.6.tgz", + "integrity": "sha512-CFHvP9Qz98NruJiUnCe61O6GveKKHpJLloXbDSWRhqhkJdZD2zU5hG+gtVJR//tyW897izuHpM6Gtf6+sNgJPQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "examples/next-13/node_modules/@next/swc-win32-arm64-msvc": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-13.5.6.tgz", + "integrity": "sha512-aFv1ejfkbS7PUa1qVPwzDHjQWQtknzAZWGTKYIAaS4NMtBlk3VyA6AYn593pqNanlicewqyl2jUhQAaFV/qXsg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "examples/next-13/node_modules/@next/swc-win32-ia32-msvc": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-13.5.6.tgz", + "integrity": "sha512-XqqpHgEIlBHvzwG8sp/JXMFkLAfGLqkbVsyN+/Ih1mR8INb6YCc2x/Mbwi6hsAgUnqQztz8cvEbHJUbSl7RHDg==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "examples/next-13/node_modules/@next/swc-win32-x64-msvc": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-13.5.6.tgz", + "integrity": "sha512-Cqfe1YmOS7k+5mGu92nl5ULkzpKuxJrP3+4AEuPmrpFZ3BHxTY3TnHmU1On3bFmFFs6FbTcdF58CCUProGpIGQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "examples/next-13/node_modules/next": { + "version": "13.5.6", + "resolved": "https://registry.npmjs.org/next/-/next-13.5.6.tgz", + "integrity": "sha512-Y2wTcTbO4WwEsVb4A8VSnOsG1I9ok+h74q0ZdxkwM3EODqrs4pasq7O0iUxbcS9VtWMicG7f3+HAj0r1+NtKSw==", + "dependencies": { + "@next/env": "13.5.6", + "@swc/helpers": "0.5.2", + "busboy": "1.6.0", + "caniuse-lite": "^1.0.30001406", + "postcss": "8.4.31", + "styled-jsx": "5.1.1", + "watchpack": "2.4.0" + }, + "bin": { + "next": "dist/bin/next" + }, + "engines": { + "node": ">=16.14.0" + }, + "optionalDependencies": { + "@next/swc-darwin-arm64": "13.5.6", + "@next/swc-darwin-x64": "13.5.6", + "@next/swc-linux-arm64-gnu": "13.5.6", + "@next/swc-linux-arm64-musl": "13.5.6", + "@next/swc-linux-x64-gnu": "13.5.6", + "@next/swc-linux-x64-musl": "13.5.6", + "@next/swc-win32-arm64-msvc": "13.5.6", + "@next/swc-win32-ia32-msvc": "13.5.6", + "@next/swc-win32-x64-msvc": "13.5.6" + }, + "peerDependencies": { + "@opentelemetry/api": "^1.1.0", + "react": "^18.2.0", + "react-dom": "^18.2.0", + "sass": "^1.3.0" + }, + "peerDependenciesMeta": { + "@opentelemetry/api": { + "optional": true + }, + "sass": { + "optional": true + } + } + }, "examples/no-src-folder": { "version": "0.1.0", "dependencies": { @@ -2000,6 +2203,10 @@ } } }, + "node_modules/next-13": { + "resolved": "examples/next-13", + "link": true + }, "node_modules/next-public-ts": { "resolved": "packages/next-public-ts", "link": true diff --git a/packages/next-public-ts/package.json b/packages/next-public-ts/package.json index ff0afba..55e344c 100644 --- a/packages/next-public-ts/package.json +++ b/packages/next-public-ts/package.json @@ -34,6 +34,6 @@ "public" ], "peerDependencies": { - "next": "^14.0.0" + "next": "^13.5.0 || ^14.0.0" } } diff --git a/packages/next-public-ts/src/index.ts b/packages/next-public-ts/src/index.ts index ac76493..dd23419 100644 --- a/packages/next-public-ts/src/index.ts +++ b/packages/next-public-ts/src/index.ts @@ -1,5 +1,4 @@ import { transformSync } from "next/dist/build/swc/index.js"; -import { webpack } from "next/dist/compiled/webpack/webpack"; import { existsSync, mkdirSync, @@ -9,6 +8,7 @@ import { writeFileSync, } from "node:fs"; import { join as pathJoin, sep as pathSep } from "node:path"; +import type { Compiler } from "webpack"; function compileDirectory(inputDir: string, outputDir: string) { if (!existsSync(inputDir)) { @@ -81,8 +81,8 @@ class NextPublicTsPlugin { this.outputDir = outputDir; } - apply(compiler: webpack.Compiler) { - compiler.hooks.afterEmit.tap("CopyPublicPlugin", (): void => { + apply(compiler: Compiler) { + compiler.hooks.afterEmit.tap("NextPublicTsPlugin", (): void => { for (const inputDir of this.inputDir) { compileDirectory(inputDir, this.outputDir); }