-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: Support transpiling external modules #1423
Comments
i m having same issue. need an ability to transpile local modules in a monorepo. |
thanks to this solution given to overide esbuild config i was able to build my local packages. i created added following code to allow custom packages const esbuild = require('esbuild');
const Module = require('module');
function manualExternalsPlugin() {
return {
name: 'manual-externals-overide',
setup(build) {
build.onResolve(
{
filter: /@YourNamespaceOrPackageName/,
},
(args) => {
return {
external: false,
namespace: args.path,
};
},
);
},
};
}
const originalRequire = Module.prototype.require;
const originalBuild = esbuild.build;
function build(options) {
if (options.platform === 'node') {
const { plugins } = options;
const externalPlugin = plugins.find(
(plugin) => plugin.name === 'manual-externals',
);
const localPlugins = plugins.filter(
(plugin) => plugin.name !== 'manual-externals',
);
localPlugins.push(manualExternalsPlugin());
localPlugins.push(externalPlugin);
return originalBuild({
...options,
plugins: localPlugins,
});
}
return originalBuild({
...options,
});
}
Module.prototype.require = function (id) {
// when remix requires esbuild, it will get our modified build function from above
if (id === 'esbuild') {
return { ...esbuild, build };
}
return originalRequire.apply(this, arguments);
}; then added following scripts "scrips": {
"dev:patched": "NODE_OPTIONS='-r ./esbuild-overrides' remix dev",
"build:patched": "NODE_OPTIONS='-r ./esbuild-overrides' remix build"
} |
fyi - transpile modules can be added to remix by just updating a few lines of code I came up with this a few months ago https://gist.github.com/cj/c6d7a3b1fcf238073951762747c201ba you can now just add /**
* @type {import('@remix-run/dev/config').AppConfig}
*/
module.exports = {
appDirectory: 'app',
browserBuildDirectory: './public/build',
publicPath: '/build/',
serverBuildDirectory: './server/build',
devServerPort: 8002,
transpileModules: ['ui', 'lib', 'env'],
} |
@airjp73 @hannadrehman I created a pull request here #1806 |
@cj this is great. thanks. |
This did not work for me. I get an error |
This feature has been implemented in the latest release, although would be also helpful to watch those files and hot reload the browser. Someone currently has a workaround #here. |
Implemented. |
Which feature is this in reference to? #1806 was closed without merge.
serverDependenciesToBundle: ["@my-namespace/other-package"],
Edit: not sure what I was doing wrong earlier, |
I cannot get this to work. I'm working with I'm trying to port over an existing Next.js application where it was working using Edit: I see now that |
@garretteklof not sure if this will help with your issue, but I just ran into it: I'm working in a monorepo and remix is one of many packages laid out via npm workspaces. I had |
I am getting this warning in the console (though the dev server seems to work nonetheless):
If I change the import in the route to I had added |
What is the new or updated feature that you are suggesting?
It would be great to have the ability to have the remix compiler transpile local modules when working in a monorepo. Essentially this would be a remix equivalent to next-transpile-modules.
One way to get this done currently is via a patch outlined in this gist. In the patch, there's a new config option in
remix.config.js
.I believe this issue is also related to #1398. Looking at the compiler code, if we had the ability the bundle all server dependencies that might also solve the issue.
The exact implementation is not super important to me -- I'm more interested in the ability to do this than the api itself.
Why should this feature be included?
It would be very useful for monorepos containing a remix app to be able to have the remix compiler transpile local modules from the monorepo. This makes it really simple & easy to create internal packages to share across multiple apps without the added friction of setting up a build step for each one.
This change also doesn't require opening up esbuild configuration options directly. The patch does touch remix's custom externals plugin, but this shouldn't impact remix's ability to switch compilers. If the remix team decided to switch another compiler, this could be done without breaking the api for this feature (though the functionality would have to be replicated with the other compiler).
The text was updated successfully, but these errors were encountered: