Skip to content
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

merge getCustomTransformers instead of replacing it #1

Closed
colorcube opened this issue Jan 5, 2023 · 2 comments
Closed

merge getCustomTransformers instead of replacing it #1

colorcube opened this issue Jan 5, 2023 · 2 comments

Comments

@colorcube
Copy link
Owner

AFAIK the problem with overriding Nx's own ts-loader transformer is that it'll then no longer support Nx's build cache

Here are some examples how to merge getCustomTransformers:

@colorcube
Copy link
Owner Author

colorcube commented Jan 5, 2023

build cache works with following webpack config
if deepkit transformer works too has to be tested

webpack-deepkit.config.js:

const typeCompiler = require('@deepkit/type-compiler');

module.exports = (config, _context) => {
    config.module.rules
        .filter((rule) => rule.loader?.includes('ts-loader'))
        .forEach((tsRule) => {
            tsRule.options.getCustomTransformers = addDeepkitTransformer(tsRule.options.getCustomTransformers)
        });


    return config
};

// this enables @deepkit/type's type compiler
function addDeepkitTransformer(prevGetCustomTransformers) {
    return (program) => {
        const customTransformers = { ...(prevGetCustomTransformers ? prevGetCustomTransformers(program) : undefined) };
        customTransformers.before = [
            typeCompiler.transformer,
            ...(customTransformers.before || [])
        ];
        customTransformers.afterDeclarations = [
            typeCompiler.declarationTransformer,
            ...(customTransformers.afterDeclarations || [])
        ];
        // console.log(customTransformers);
        return customTransformers
    }
}

@colorcube
Copy link
Owner Author

I think I managed to add the Deepkit transformer to getCustomTransformers and preserve the Nx transformer.
Nx build cache works again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant