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

preact debug mode with ES6 imports #1746

Closed
damianobarbati opened this issue Jun 30, 2019 · 4 comments
Closed

preact debug mode with ES6 imports #1746

damianobarbati opened this issue Jun 30, 2019 · 4 comments

Comments

@damianobarbati
Copy link

The docs are showing require usage but what's the correct way to import this with ES6 and only in development?

The following is indeed not working: proptypes validation is enabled after components are mounted thus those are not validated.

if (module.hot) {
    module.hot.accept();
    import('preact/debug');
}

The following on top of index.js mean including also in production the debug logic.

import 'preact/debug'; //eslint-disable-line

Any help?
My hint: preact/debug should export a function, this allows the developer to import it and run it only if NODE_ENV=development and tree-shake it away in production.

PS: great work guys!

@sventschui
Copy link
Member

sventschui commented Jun 30, 2019

The problem about es6 imports in this case is that they are static. One might not make them conditional by design. The dynamic import you mentioned makes this possible, but adds the preact options too late and thus some things might not work.

As far as I know there should not be any drawback on using a require together with es6 imports. As far as I know when using if (process.env.NODE_ENV==='development') { require('preact/debug'); } the statement will be dead-code-eliminated during uglify and thus not end up in your prod bundle at all, or does it in your case? Is there any particular reason why you'd want it to be es6?

If you really want this and you are using webpack you could use the null-loader for your production build

@jeremy-coleman
Copy link
Contributor

jeremy-coleman commented Jul 5, 2019

That syntax isnt es6 import, its dynamic import whose sole purpose is to delay loading. Import thing and export thing is the es module syntax , but im not sure that really means anything if you use webpack. The output generated isnt anything close to es module, i would argue closer to amd than anything. Basically,Just use what works bc it doesnt matter

@marvinhagemeister
Copy link
Member

marvinhagemeister commented Jul 7, 2019

Closing, @sventschui and @jeremy-coleman summed up the situation perfectly 👍

@damianobarbati
Copy link
Author

I understand, but can't preact/debug handle the logic just as prop-types does? Relieving the developer from manually doing that?

https://github.com/facebook/prop-types/blob/master/index.js#L8

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