Skip to content

Commit

Permalink
chore(rwjs/vite): Rename build script and format source (#11163)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobbe authored Aug 6, 2024
1 parent b925930 commit a34e23f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
47 changes: 31 additions & 16 deletions packages/vite/build.mts → packages/vite/build.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { writeFileSync } from 'node:fs'

import { commonjs } from '@hyrious/esbuild-plugin-commonjs'
import * as esbuild from 'esbuild'

import {
build,
defaultBuildOptions,
defaultIgnorePatterns,
} from '@redwoodjs/framework-tools'

import { writeFileSync } from 'node:fs'
import { commonjs } from '@hyrious/esbuild-plugin-commonjs'

import * as esbuild from 'esbuild'

// CJS Build
await build({
entryPointOptions: {
Expand Down Expand Up @@ -43,28 +43,43 @@ await esbuild.build({
conditions: ['react-server'],
platform: 'node',
target: ['node20'],
// ⭐ Without this plugin, we get "Error: Dynamic require of "util" is not supported"
// when trying to run the built files. This plugin will
// "just rewrite that file to replace "require(node-module)" to a toplevel static import statement." (see issue)
// Without this plugin, we get "Error: Dynamic require of "util" is not
// supported" when trying to run the built files. This plugin will "just
// rewrite that file to replace "require(node-module)" to a toplevel static
// import statement." (see issue)
// https://github.com/evanw/esbuild/issues/2113
// https://github.com/evanw/esbuild/pull/2067
plugins: [commonjs()],
logLevel: 'info',
})

// Place a package.json file with `type: commonjs` in the dist/cjs folder so that
// all .js files are treated as CommonJS files.
// Place a package.json file with `type: commonjs` in the dist/cjs folder so
// that all .js files are treated as CommonJS files.
writeFileSync('dist/cjs/package.json', JSON.stringify({ type: 'commonjs' }))

// Place a package.json file with `type: module` in the dist folder so that
// all .js files are treated as ES Module files.
writeFileSync('dist/package.json', JSON.stringify({ type: 'module' }))

// Add CommonJS types by creating common JS types. Using a .d.ts file, because .d.cts files don't auto resolve
// Notice I haven't specified thee types in package.json for these - it's following the naming conversion TSC wants.
// Add CommonJS types by creating common JS types. Using a .d.ts file, because
// .d.cts files don't auto resolve
// Notice I haven't specified the types in package.json for these - it's
// following the naming conversion TSC wants.
writeFileSync('dist/cjs/index.d.ts', 'export type * from "../index.d.ts"')
writeFileSync('dist/cjs/buildFeServer.d.ts', 'export type * from "../buildFeServer.d.ts"')
writeFileSync(
'dist/cjs/buildFeServer.d.ts',
'export type * from "../buildFeServer.d.ts"',
)
writeFileSync('dist/cjs/client.d.ts', 'export type * from "../client.d.ts"')
writeFileSync('dist/cjs/clientSsr.d.ts', 'export type * from "../clientSsr.d.ts"')
writeFileSync('dist/cjs/ClientRouter.d.ts', 'export type * from "../ClientRouter.d.ts"')
writeFileSync('dist/cjs/build/build.d.ts', 'export type * from "../../build/build.d.ts"')
writeFileSync(
'dist/cjs/clientSsr.d.ts',
'export type * from "../clientSsr.d.ts"',
)
writeFileSync(
'dist/cjs/ClientRouter.d.ts',
'export type * from "../ClientRouter.d.ts"',
)
writeFileSync(
'dist/cjs/build/build.d.ts',
'export type * from "../../build/build.d.ts"',
)
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"inject"
],
"scripts": {
"build": "tsx build.mts && yarn build:types",
"build": "tsx build.ts && yarn build:types",
"build:pack": "yarn pack -o redwoodjs-vite.tgz",
"build:types": "tsc --build --verbose ./tsconfig.json",
"check:attw": "tsx ./attw.ts",
Expand Down

0 comments on commit a34e23f

Please sign in to comment.