Skip to content

How to exclude some code when building for production? #3110

Answered by adamlindqvist
samadadi asked this question in Q&A
Discussion options

You must be logged in to vote

@samadadi

I'm doing it like this to exclude msw from the production bundle:

// index.tsx

async function prepare() {
    if (import.meta.env.DEV) {
        const { worker } = await import('./mocks/browser');

        return worker.start();
    }
}

prepare().then(() => {
    ReactDOM.render(
        <React.StrictMode>
            <App />
        </React.StrictMode>,
        document.getElementById('root')
    );
});

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@florianmatz
Comment options

@apdrsn
Comment options

@cchangwen
Comment options

Answer selected by Shinigami92
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
6 participants