-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for multiple bundlers and module systems
- Loading branch information
Showing
10 changed files
with
1,559 additions
and
2,247 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,9 @@ | ||
import type { InitialOptionsTsJest } from "ts-jest"; | ||
import type { Config } from "jest"; | ||
|
||
module.exports = <InitialOptionsTsJest>{ | ||
const config: Config = { | ||
preset: "ts-jest/presets/default-esm", | ||
testEnvironment: "node", | ||
globals: { | ||
"ts-jest": { | ||
// ts-jest needs to be told to use ESM. Choosing | ||
// an esm preset for ts-jest doesn't imply useEsm (??). | ||
useESM: true, | ||
}, | ||
}, | ||
extensionsToTreatAsEsm: [".ts"], | ||
}; | ||
|
||
export default config; |
Large diffs are not rendered by default.
Oops, something went wrong.
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,33 @@ | ||
import { transformAsync } from "@babel/core"; | ||
import { createWebpackPlugin } from "unplugin"; | ||
import type { UnpluginOptions } from "unplugin"; | ||
import plugin from "./plugin.js"; | ||
import { CSSModuleError } from "./utils.js"; | ||
|
||
function unpluginFactory(): UnpluginOptions { | ||
return { | ||
name: "jsx-css-module-transforms", | ||
|
||
transformInclude(id) { | ||
const result = /\.tsx?$/i.test(id); | ||
return result; | ||
}, | ||
|
||
async transform(code, id) { | ||
// babel's transformSync cannot be used with ESM based plugin | ||
const result = await transformAsync(code, { | ||
filename: id, | ||
plugins: ["@babel/plugin-syntax-jsx", plugin], | ||
sourceMaps: process.env.NODE_ENV == "production" ? false : "inline", | ||
}); | ||
|
||
if (!result?.code) { | ||
throw new CSSModuleError(`Could not transform ${id}`); | ||
} | ||
|
||
return result.code; | ||
}, | ||
}; | ||
} | ||
|
||
export default createWebpackPlugin(unpluginFactory); |
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
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,22 @@ | ||
import { defineConfig } from "tsup"; | ||
|
||
export default defineConfig({ | ||
clean: true, | ||
dts: true, | ||
|
||
// Bundle optimizations | ||
treeshake: false, // When true, generates broken commonjs code | ||
splitting: false, | ||
minify: false, | ||
|
||
// Transforms esm's `import.meta.url` to its cjs alternative and cjs's `__dirname` to its esm alternative | ||
shims: true, | ||
|
||
// Prod build options | ||
entry: ["src/index.ts"], | ||
outDir: "dist", | ||
format: ["cjs", "esm"], | ||
cjsInterop: true, | ||
sourcemap: false, | ||
bundle: true, | ||
}); |
Oops, something went wrong.