-
-
Notifications
You must be signed in to change notification settings - Fork 381
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
fix issue with @loadable/webpack-plugin not working in production mode and SSR #187
Conversation
…pecyfying where loadable-stats are written to when writeToDisk option is set to true
…al('module.require') was throwing errors server side
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry but it does not work. Your path option is only used if writeToDisk
is set to true
. It is confusing. All webpack assets are generated into outputPath
, so what should we specify another path for this specific file? I think the path
option is not relevant.
} | ||
|
||
// eslint-disable-next-line global-require, import/no-dynamic-require | ||
return require(modulePath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that it will not cause any error or warning when built using webpack?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, tried that with razzle that uses webpack for the server bundle as well
@tadeuszwojcik thanks for your work, but it is important to keep it consistent and compliant with webpack ecosystem. |
@neoziro thanks for taking the time and looking into this, I've used the path in the same way that https://github.com/ztoben/assets-webpack-plugin/blob/master/readme.md uses, happy to continue this conversation after Christmas as I'm on holidays right now. Please don't close/rejected it before then, I'll try to put more details about rationale of this pull request and why it's essential for razzle and razzle like setups! Thanks! |
@tadeuszwojcik OK, if |
@neoziro What is the status of this issue? Is there anything that you would like to change and/or you are not sure about? Maybe I can help somehow? From my perspective changes done by @tadeuszwojcik are ok. Actually, many webpack loaders/plugins follow that pattern were output path can be overridden, e.g. file-loader |
@tutok my concern is that is an absolute output path is specified it will be written in two different folders: https://github.com/smooth-code/loadable-components/pull/187/files#diff-567a0d765f93649fdd2c856a649ba64bR29 I think it is not good. This is the only blocking point. |
@tadeuszwojcik @neoziro
currently we are using webpack dev server for client bundle and output is
where asset.json absolute build path. we can check this logic that I used as reference back then. |
With the actual code, stats will be written two times if new LoadablePlugin({ writeToDisk: { filename: '/your/custom/path/loadable-stats.json' } }) This way it is clear that the asset will be written to disk at a specific location. We can also add a config option What do you think? |
@neoziro you mean btw. is even |
@tutok yeah this is what I mean for |
…name instead of being boolean flag
@neoziro I've pushed the change with |
I am sorry, I would like you to make one last change to make it easy for users:
Can you also add a
This way we could do: new LoadablePlugin({ outputAsset: false, writeToDisk: { filename: 'my/custom/stats.json' }) I think the API is great and can handle all cases. |
@neoziro I don't think you last comment was for this issue. Probably should not close this ticket either |
Oups sorry! |
@tadeuszwojcik any update? |
- outputAsset option boolean flag - change writeToDisk option to accept true/false of filename
@neoziro sorry for delay, I've updated plugin with new API as requested, hope it's fine now. I didn't have time for updating docs yet, so hopefully someone else would be able to cover that. Thanks! |
@neoziro can we merge? |
Thanks for your work! |
This is my stab at #179 .
I've added
path
option to the webpack plugin, that allows specifying where loadable-stats are written to whenwriteToDisk
option is set to true. This way webpack assets compiler always usefilename
and not absolute path when adding loadable stats to the assets. Ifpath
is not set by default loadable-stats are written tooutput.path
set in webpack config.I also fixed issue I had with
eval('module.require')
trick as it was throwing errors (eval is not a function). I've replaced it with__non_webpack_require__
and that seems to be working fine.I've tested it with razzle example in the repo and it works fine both in dev and production mode (after yarn build command).
Closes #179