Skip to content

Commit

Permalink
build: switch from CommonJS to ESM
Browse files Browse the repository at this point in the history
- Add `type: module` to `package.json`.
- Update `next.config.js` and `postcss.config.js` to use `import/export`.
- Replace `ts-node` with `tsx` for running TypeScript in Node.
- Update `tsconfig.json` to use `esnext`.
  • Loading branch information
eatyourgreens committed Nov 18, 2024
1 parent 81a595f commit e0af18d
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 143 deletions.
7 changes: 4 additions & 3 deletions next.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/** @type {import('next').NextConfig} */
const withBundleAnalyzer = require("@next/bundle-analyzer")({
import bundleAnalyzer from "@next/bundle-analyzer"
const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env.ANALYZE === "true",
})
const { withPlausibleProxy } = require("next-plausible")
import { withPlausibleProxy } from "next-plausible"

const nextConfig = {
reactStrictMode: true,
Expand Down Expand Up @@ -40,4 +41,4 @@ const nextConfig = {
},
}

module.exports = withPlausibleProxy()(withBundleAnalyzer(nextConfig))
export default withPlausibleProxy()(withBundleAnalyzer(nextConfig))
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"name": "gutenberg",
"version": "0.1.0",
"private": true,
"type": "module",
"scripts": {
"format": "prettier --write \"**/*.{ts,tsx,js,md,mdx,css,yaml}\"",
"format:check": "prettier --check \"**/*.{ts,tsx,js,md,mdx,css,yaml}\"",
Expand All @@ -13,12 +14,12 @@
"e2e": "start-server-and-test 'yarn dev' http://127.0.0.1:3000 \"dotenv -e .env.local -e .env cypress run --e2e\"",
"ci:e2e": "start-server-and-test 'yarn start' http://127.0.0.1:3000 \"cypress run --e2e\"",
"component": "cypress run --component",
"table": "NEXT_PUBLIC_BASEPATH='' MATERIAL_DIR=.material ts-node --skip-project --compiler-options '{\"module\":\"CommonJS\"}' scripts/table.ts",
"cron": "dotenv -e .env.local -e .env -- ts-node --skip-project --compiler-options '{\"module\":\"CommonJS\"}' scripts/cronScripts.ts",
"pullmat": "dotenv -e .env -e .env.local -- ts-node --skip-project --transpile-only --compiler-options '{\"module\":\"CommonJS\"}' scripts/pullMaterial.ts"
"table": "NEXT_PUBLIC_BASEPATH='' MATERIAL_DIR=.material tsx scripts/table.ts",
"cron": "dotenv -e .env.local -e .env -- tsx scripts/cronScripts.ts",
"pullmat": "dotenv -e .env -e .env.local -- tsx scripts/pullMaterial.ts"
},
"prisma": {
"seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
"seed": "ts-node --esm --compiler-options {\"module\":\"ESNext\"} prisma/seed.ts"
},
"dependencies": {
"@dnd-kit/core": "^3.0.0",
Expand Down Expand Up @@ -102,7 +103,7 @@
"jose": "^4.15.5",
"prisma": "^4.11.0",
"start-server-and-test": "^2.0.0",
"ts-node": "^10.9.1",
"tsx": "^4.19.2",
"typescript": "5.6.2"
},
"packageManager": "[email protected]",
Expand Down
2 changes: 1 addition & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"baseUrl": ".",
"target": "es5",
"target": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": false,
"skipLibCheck": true,
Expand All @@ -16,6 +16,9 @@
"jsx": "preserve",
"incremental": true
},
"ts-node": {
"esm": true
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"],
"exclude": ["node_modules", ".next", ".material", "out", "public", "styles"]
}
Loading

0 comments on commit e0af18d

Please sign in to comment.