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

🐞 - Unused extensions are not tree-shaken from production bundle #1412

Closed
hakimio opened this issue Sep 19, 2024 · 1 comment · Fixed by #1447 or #1461
Closed

🐞 - Unused extensions are not tree-shaken from production bundle #1412

hakimio opened this issue Sep 19, 2024 · 1 comment · Fixed by #1447 or #1461
Labels
bug Something isn't working contributions welcome Architecture is clear and community can help P3 This issue has low priority

Comments

@hakimio
Copy link
Contributor

hakimio commented Sep 19, 2024

Code Example URL

stackblitz.com

Description

Even if you customize the editor's extensions using TUI_EDITOR_EXTENSIONS provider, the production bundle still includes all the unused extensions like markdown and prosemirror-tables.

import type {Extension, Mark, Node} from '@tiptap/core';
import {TUI_EDITOR_EXTENSIONS, TuiStarterKit, TuiTabExtension, TuiLink} from '@taiga-ui/editor';
import {type ApplicationConfig} from '@angular/core';

const TUI_EDITOR_DEFAULT_EXTENSIONS: ReadonlyArray<
    Extension | Mark | Node | Promise<Extension | Mark | Node>
> = [
    TuiStarterKit.configure({
        heading: false,
        code: false,
        codeBlock: false,
        dropcursor: false,
        gapcursor: false
    }),
    import('@tiptap/extension-text-style').then(({default: textStyle}) => textStyle),
    import('@tiptap/extension-underline').then(({default: underline}) => underline),
    TuiLink,
    TuiTabExtension
];

export const appConfig: ApplicationConfig = {
    providers: [{
        provide: TUI_EDITOR_EXTENSIONS,
        useValue: TUI_EDITOR_DEFAULT_EXTENSIONS
    }]
};

image

Additional info

Angular: 18.2.5
Builder: @angular/build:application (based on esbuild)

ng build --stats-json can be used to generates a stats.json file which can be analyzed with esbuild bundle analyzer.

It might be needed to provide secondary entrypoints like in Angular Material project to have proper bundle tree-shaking
ng-packagr explanation on how to add secondary entrypoints

image

Taiga UI version

4.7.0

Browser Used

Chrome

OS Used

Windows

@hakimio hakimio added bug Something isn't working state: need triage state need triage labels Sep 19, 2024
@splincode splincode added community contribution This issue was closed by a PR from the community contributions welcome Architecture is clear and community can help P3 This issue has low priority and removed state: need triage state need triage labels Sep 19, 2024
@waterplea waterplea removed the community contribution This issue was closed by a PR from the community label Sep 19, 2024
@hakimio
Copy link
Contributor Author

hakimio commented Sep 25, 2024

@splincode I have some good news and some bad news.

Good news
Tree-shaking seems to work now and I get 200+ KB production bundle size reduction when using deep imports like import {TuiTabExtension} from '@taiga-ui/editor/extensions/indent-outdent';

Bad news
Using short imports like import {TuiTabExtension} from '@taiga-ui/editor'; results in some build errors:
https://gist.github.com/hakimio/4646371ff531c8d19bfe8e65cc8d0e65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working contributions welcome Architecture is clear and community can help P3 This issue has low priority
Projects
None yet
3 participants