Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce esm and cjs support according to d3/d3#3469 (comment)
- Loading branch information
Showing
6 changed files
with
225 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import ts from '@rollup/plugin-typescript' | ||
import { promises as fs } from "fs" | ||
|
||
const isCJSBuild = process.env.MODE === "cjs" | ||
|
||
const commonjsPkgJSONPlugin = () => { | ||
return { | ||
name: 'commonjsPkgJSONPlugin', | ||
write: async () => { | ||
await fs.writeFile("dist/cjs/package.json", JSON.stringify({ | ||
"type": "commonjs" | ||
})) | ||
} | ||
} | ||
} | ||
|
||
export default { | ||
input: ['src/index.ts', 'src/relay.ts'], | ||
output: [ | ||
{ | ||
dir: isCJSBuild ? 'dist/cjs' : 'dist', | ||
format: isCJSBuild ? 'cjs' : 'esm' | ||
} | ||
], | ||
plugins: [ts({ tsconfig: isCJSBuild ? "tsconfig.cjs.json" : "tsconfig.json" }), isCJSBuild ? commonjsPkgJSONPlugin() : undefined].filter(Boolean), | ||
external: ["graphql"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist/cjs", | ||
"declaration": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"incremental": true, /* Enable incremental compilation */ | ||
"target": "es2019", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */ | ||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ | ||
"jsx": "react", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ | ||
"target": "ES2019", | ||
"module": "ESNext", | ||
"moduleResolution": "node", | ||
"rootDir": "src", | ||
"outDir": "dist", /* Redirect output structure to the directory. */ | ||
"outDir": "dist", | ||
"declaration": true, | ||
/* Strict Type-Checking Options */ | ||
"strict": true, /* Enable all strict type-checking options. */ | ||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ | ||
"noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ | ||
"alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ | ||
|
||
"strict": true, | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"alwaysStrict": true, | ||
/* Additional Checks */ | ||
"noUnusedLocals": true, /* Report errors on unused locals. */ | ||
"noUnusedParameters": true, /* Report errors on unused parameters. */ | ||
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ | ||
"noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ | ||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ | ||
"emitDeclarationOnly": true | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": true | ||
}, | ||
"files": ["./src/index.ts", "./src/relay.ts"] | ||
} |
Oops, something went wrong.