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

Feature: Loaders API: add method to get outputOptions #8535

Closed
aarefiev opened this issue Dec 21, 2018 · 16 comments
Closed

Feature: Loaders API: add method to get outputOptions #8535

aarefiev opened this issue Dec 21, 2018 · 16 comments
Labels

Comments

@aarefiev
Copy link

aarefiev commented Dec 21, 2018

Feature request

What is the expected behavior?
I would be nice to have ability to get formatted outputOptions like this._compilation.outputOptions but without using structure hacking.

What is motivation or use case for adding/changing the behavior?
I found that some of output options not working as I expected. Some days ago I configured webpack based project with output.hashDigestLength option. But when I set it, only bundled files and files processed by plug-ins are ha truncated names as I expected, but files that processed by loaders only are not.

I did not understand what was wrong, because the documentation says

The lengths of [hash] and [chunkhash] can be specified using [hash:16] (defaults to 20). Alternatively, specify output.hashDigestLength to configure the length globally.

According to documentation all plug-ins has access to outputOptions through Hooks API. But loaders are not. I think it is not good 👎

How should this be implemented in your opinion?
I think in Loaders API should be a method to get formatted outputOptions.

Are you willing to work on this yourself?
yes, sure

@mc-zone
Copy link
Member

mc-zone commented Jan 13, 2019

You can visit this._compilation.outputOptions.hashDigestLength to get this config and the value has been validated. I'm not sure what the exact formatted outputOptions you point is? Could you please provide a mini repo to reproduce your problem?

@aarefiev
Copy link
Author

@mc-zone

You can visit this._compilation.outputOptions.hashDigestLength to get this config and the value has been validated

The this._compilation option is hacky access to the Compilation object of webpack. Is there any way to get output options without hacking? I didn't found API method to get.

I'm not sure what the exact formatted outputOptions you point is?

As "formatted" I mean options from compiler after init. Sorry for the wrong explanation.

Could you please provide a mini repo to reproduce your problem?

I sent pr for webpack/loader-utils (webpack/loader-utils#120). As you can see there, I using option from this._compilation object, but as @evilebottnawi says, it is wrong way (https://github.com/webpack/loader-utils/pull/120/files#diff-8e83cc01b69358d1f366c2c32b490456R67).

@alexander-akait
Copy link
Member

@mc-zone we need api for this because in future it can be changes, using _* options are hacky

@mc-zone
Copy link
Member

mc-zone commented Jan 14, 2019

@evilebottnawi Oh yes. These _* API has been marked as deprecated for so long.

But AFAIK, this._compilation still exist in webpack 5 and some other main loaders also using it (like the loader part of mini-css-extract-plugin)

It might frequently be used. should we make it public?

@aarefiev
Copy link
Author

@mc-zone If that we can create method this.compilation as a reference to this._compilation. If this._compilation will changed in future we can update this.compilation only but without updating loaders.

I can work on it if possible.

@sokra
Copy link
Member

sokra commented Jan 15, 2019

this._* is not deprecated, it's private. Loaders can use it on it's own risk. When using it you should expect that the loader breaking on major webpack releases. Basically it's more a plugin than a loader. The public loader API is more stable and probably won't break/change on major releases. It's also not webpack specific so technically you could use it in other things (there is a loader-runner npm package for that).

Exposing outputOptions on the public API would break that assumption, as outputOptions is pretty webpack-specific and may change between versions. So if we would expose it, it would probably exposed as this._outputOptions. And this won't have a benefit over this._compilation.outputOptions.

@sokra
Copy link
Member

sokra commented Jan 15, 2019

So: Use this._compilation.outputOptions and add the supported webpack versions as peerDependencies.

@alexander-akait
Copy link
Member

@sokra we need this in loader-utils, they are used in many loaders/plugins and will be great do stable api, without private access to avoid breaking between difference webpack version

@aarefiev
Copy link
Author

@sokra what about making this._compilation public? Is there any reason not to do this?

@alexander-akait
Copy link
Member

alexander-akait commented Feb 19, 2019

/cc @aarefiev friendly ping, we can implement getHashOutputOptions and return all hash* options from compilation. No need to make the compilation public.

@aarefiev
Copy link
Author

@evilebottnawi thanks

@webpack-bot
Copy link
Contributor

This issue had no activity for at least half a year.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@alexander-akait
Copy link
Member

Bump

@webpack-bot
Copy link
Contributor

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

@alexander-akait
Copy link
Member

Bump

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants