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

Add script config for adding scripts as type="module" #24592

Closed
tmcconechy opened this issue Jan 23, 2023 · 5 comments
Closed

Add script config for adding scripts as type="module" #24592

tmcconechy opened this issue Jan 23, 2023 · 5 comments
Labels
area: @angular-devkit/build-angular devkit/build-angular:browser feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature

Comments

@tmcconechy
Copy link

tmcconechy commented Jan 23, 2023

Command

build, config

Description

Looking at the script config https://angular.io/guide/workspace-config#style-script-config there does not seem to be any way to add the scripts as type="module" for esm.

If the third party script is delivered as an Es Module it cant be imported in the angular.json.

Screenshot 2023-01-23 at 11 30 28 AM

Seems like there is some thought about this

This comment may be the one of why it won't add type="module"

// Also, non entrypoints need to be loaded as no module as they can contain problematic code.
-> but still think it should be possible.

Describe the solution you'd like

Add a new setting to the script config, something like.

"scripts": [
  {
    "input": "node_modules/third-party/esm-script.js", 
    "inject": true,
    "scriptType": "module"
   }
],

Describe alternatives you've considered

  • can not use angular.json and
  • manually add a script tag or
  • just import the module in the Angular module code
@angular-robot angular-robot bot added the feature: votes required Feature request which is currently still in the voting phase label Jan 24, 2023
@angular-robot
Copy link
Contributor

angular-robot bot commented Jan 24, 2023

This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list.

You can find more details about the feature request process in our documentation.

@angular-robot angular-robot bot added feature: under consideration Feature request for which voting has completed and the request is now under consideration and removed feature: votes required Feature request which is currently still in the voting phase labels Jan 26, 2023
@egorwow70
Copy link

@alan-agius4
Hello, Alan. Is there any update regarding this issue?

@bernatgy
Copy link

Also interested if there is any progress in this... It's quite serious, because some third party libs started shipping/working with exclusively .mjs files. (eg. mozilla/pdf.js)

@alan-agius4
Copy link
Collaborator

When the script is in ESM, you can directly import it in main.ts or wherever it's required.

@bernatgy, it's preferable to use the explicitly imported script instead of relying on the prebuilt global script. This ensures that Dead Code Elimination (DCE) and tree-shaking optimizations can be applied to the library.

Example:

import { getDocument } from "pdfjs-dist";
const loadingTask = getDocument(pdfPath);

The scripts option should only be used for legacy scripts that are not ESM complaint.

@alan-agius4 alan-agius4 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2024
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators May 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: @angular-devkit/build-angular devkit/build-angular:browser feature: under consideration Feature request for which voting has completed and the request is now under consideration feature Issue that requests a new feature
Projects
None yet
Development

No branches or pull requests

4 participants