Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a new
tsconfig.cjs.json
that extends the default tsconfig, but changes compilation target to CommonJS. The CommonJS code is output todist/cjs
and thus doesn't interfere with the ESM code indist
.For node to pick up the CJS code, I changed the
main
field inpackage.json
to the CJS directory, but set bothmodule
andreact-native
to the ESM directory.Note however, that this still doesn't work completely since
react-native
(which doesn't ship CommonJS code) is imported inClassParser.ts
andindex.ts
(through theuseDeviceContext
export). Thus, node errors when it reachesrequire("react-native")
.In my specific use case, I want to import the
create
function in a Babel Plugin to statically extract and compile the Tailwind styles.To make this work, we would need to:create
function fromindex.ts
and re-export it from there (to get rid of theexport { useDeviceContext } from "./hooks"
in the same file)import { Platform as RnPlatform } from 'react-native'
inClassParser.ts
. We could achieve this by passing the Platform in the constructor for example.Then, we would be able to
require("twrnc/create")
from a node environment and benefit from all the magic you are doing around processing styles. 馃帀PS: Also see #87