Monorepo compatibility
See original GitHub issueHey team mailing, great strides over the last few weeks towards v1!
Based on v0.6.9
, I think the last missing piece to unlock usage in monorepos is adding support for path mappings. I have multiple packages in my project that import other packages, so my template could look like this.
import { veryUsefulFunction } from '@repo/package';
export function MailingTemplate() {
return (
<Layout>
<Button onClick={veryUsefulFunction}>
I want to be useful!
</Button>
</Layout>
);
}
This currently won’t work with either dev or build commands. It will fail with the module not found error message. I tried to poke in mailing to see what needs to change and it seems it’s the registerRequireHooks()
method in registerRequireHooks.ts.
I was able to manually update it to fix the module not found error, but then I ran into other issues such as:
SyntaxError: Unexpected token 'export'
SyntaxError: Cannot use import statement outside a module
Resolving these would require a more involved approach and it’s possible this has something to do with mailing itself, so I didn’t continue. Any pointers?
Issue Analytics
- State:
- Created a year ago
- Comments:21 (8 by maintainers)
Top GitHub Comments
Ya, I’ll open a pr with this some time this week.
Mailing works just fine within a monorepo. I have done the following to get it configured correctly.
package.json
, and adjust the name to match your monorepo structure, eg:@mymonorepor/email
package to relative imports when we build the package.tsconfig.json
: You will need to edit thepaths
array to match your monorepo schema.packages/email
calledemails
. I find this to be redundant. I have copied all of these files out ofemails
into the root ofpackages/email
. The abovetsconfig.json
is setup for this. If you want to keep everything inemails
, change"include": ["."]
to"include": ["./emails"]
.@mymonorepo/email/....
.package.json
changes:main
,typings
, andscripts
index.ts
@mymonorepo/email
as a dependency to your backend packages.@mymonorepo/email
You now have a package in your monorepo for
mailing
. It will build on save intopackages/email/dist
, and work as a package for any other package.Notes:
"jsx": "react-jsx"
to thetsconfig.json
of any package that depends on@mymonorepo/email
. You will also need to change the extension of any file that callssendMail
to.tsx
. If you do not want to do this, you can call your templates as functions instead ofjsx
, egWelcome({ name: 'Foo Bar' })
.