Hi!
I have some “common” typescript packages in packages/*
that I’d like to include in the api/
build/“rw dev” babel processing.
packages/*
may be used by api/
, web/
, … - and we’d like to transpile target to be the same, as they different between api/web/…
Also, we’d like changes made to these common packages to affect the live reloading on api/
(not too concerned about web/)
We’re in RW 6.6.4, using typescript
I’ve created the file api/babel.config.js
Attempt 1:
Edit: node_modules/@redwoodjs/babel-config/dist/api.js
L153 add:
babelrcRoots: [
'.',
'./packages/*',
],
Error: Cannot find module '@my-corp/common/lib/types'
tsconfig.json
has the following line:
"include": ["web/**/*", "api/**/*", "scripts/**/*", "packages/**/*"],
And api/tsconfig.json
:
...
"../packages/**/*",
...
I was able to transpile files outside of api/ by updating
[redwood/packages/internal/src/files.ts] L66 (findWebFiles)
Adding something like this (in my local node_modules):
const basePath = (0, _projectConfig.getPaths)().base;
const pkgFiles = _fastGlob.default.sync('packages/**/*.ts', {
basePath,
absolute: true,
ignore: ignoreApiFiles
});
return [...files, ...pkgFiles];
This causes a bunch of issues:
prebuild
and dist
normally have all the api files on those directories, not in the api
directory.
e.g. used to be prebuild/*
, but now it’s prebuild/api/*
I think the best option will be to setup a separate build step.
And that step could have “watch” if required
1 Like
Glad you were able to find a solution!
This topic is a bit outside my area of expertise so am going to mention to ten rest of the team to see if they have any ideas or suggestions.
For anyone who’s hit this issue and want a bit of an explanation of what’s going on, here’s the deal:
Files to be processed/transpiled by babel/typescript are hard-coded in the redwood/packages/internal/src/files.ts
There is a corresponding Discord thread about this post:
Discord is great for playing games and chilling with friends, or even building a worldwide community. Customize your own space to talk, play, and hang out.