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

Customize type attribute of script #1663

Open
chenxsan opened this issue Jun 30, 2021 · 6 comments
Open

Customize type attribute of script #1663

chenxsan opened this issue Jun 30, 2021 · 6 comments

Comments

@chenxsan
Copy link
Contributor

Is your feature request related to a problem? Please describe.

As of 5.41.0, webpack will output .mjs by default when experimental ECMAScript modules support is enabled. You can see a demo here.

I'm wondering if html-webpack-plugin can support customizing the type attribute of script element:

<script type='module' src=''></script>

Describe the solution you'd like

Add type='module' to script automatically when users enable experimental ESM support in webpack.config.js.

module.exports = {
  experiments: {
    outputModule: true,
  },
};

Describe alternatives you've considered

Add a type option so users can customize as they wish.

Additional context

@jantimon
Copy link
Owner

jantimon commented Aug 2, 2021

Good idea - we already have the scriptLoading option which controls where and how tags are injected.

What about adding a new option here?

@chenxsan
Copy link
Contributor Author

chenxsan commented Aug 3, 2021

@jantimon Yeah, a new option would be suitable.

@jantimon
Copy link
Owner

jantimon commented Aug 3, 2021

I guess it could be scriptLoading: 'module' - what is the recommended way to load webpack 5 generated js modules? defer?

@chenxsan
Copy link
Contributor Author

chenxsan commented Aug 3, 2021

Modules are deferred automatically, so there's no need to set one.

noppa added a commit to noppa/html-webpack-plugin that referenced this issue Aug 6, 2021
Add third option, `'module'`, to the `scriptLoading` option.

This partially fixes issue jantimon#1663, which is also where this solution to
the problem was proposed. Although this patch doesn't give a way to
freely set `type` attribute to any value, setting `scriptLoading:
"module" now makes the scripts have attribute `type="module"`, which was
the original motivation behind the issue.
noppa added a commit to noppa/html-webpack-plugin that referenced this issue Aug 6, 2021
Add third option, `'module'`, to the `scriptLoading` option.

This partially fixes issue jantimon#1663, which is also where this solution to
the problem was proposed. Although this patch doesn't give a way to
freely set `type` attribute to any value, setting `scriptLoading:
"module" now makes the scripts have attribute `type="module"`, which was
the original motivation behind the issue.
jantimon pushed a commit that referenced this issue Oct 25, 2021
Add third option, `'module'`, to the `scriptLoading` option.

This partially fixes issue #1663, which is also where this solution to
the problem was proposed. Although this patch doesn't give a way to
freely set `type` attribute to any value, setting `scriptLoading:
"module" now makes the scripts have attribute `type="module"`, which was
the original motivation behind the issue.
@stale
Copy link

stale bot commented Apr 16, 2022

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.

@stale stale bot added the wontfix label Apr 16, 2022
@hronro
Copy link

hronro commented Apr 16, 2022

not stale

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

3 participants