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

how can i use ts-loader and webpack3 dynamic imports to implement code-splitting #652

Closed
jackie19 opened this issue Oct 13, 2017 · 4 comments

Comments

@jackie19
Copy link

code:

class Home{

    append() {

        this.getComponent().then((component) => {
            document.body.appendChild(component);
        })
    }

    getComponent() {

        return import(/* webpackChunkName: "lodash" */ 'lodash/join').then(join => {

            let element = document.createElement('div');
            element.innerHTML = join(['Hello', 'webpack'], ' ');
            return element;
        })
    }
}

var myHome = new Home()

myHome.append()

webpack code-splitting guides: https://webpack.js.org/guides/code-splitting/

@johnnyreilly
Copy link
Member

I advise taking a look at one of our execution tests that uses this approach: https://github.com/TypeStrong/ts-loader/tree/master/test/execution-tests/2.4.1_babel-importCodeSplitting

@landru29
Copy link

@johnnyreilly: the question was about using webpackChunkName in a typescriypt project

@johnnyreilly
Copy link
Member

Oh well - that's simple. It should just work. Just make sure your tsconfig.json doesn't trim comments.

@Plmeks
Copy link

Plmeks commented Apr 7, 2019

module: "esnext" and removeComments: false at tsconfig.json

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

4 participants