Problem/Motivation

No ability to include [type="module"] or [nomodule], we need to be able to render/output bother these scenarios:

<script type="module" src="https://yourdomain.com/yourscript.js"></script>
<script nomodule src="https://yourdomain.com/yourscript.js"></script>

Proposed resolution

I propose we simply add a 2 field as setting options on the JS (similar to minified, preprocess)

library

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

RobinGalipeau created an issue. See original summary.

robingalipeau’s picture

Issue summary: View changes

rishabjasrotia made their first commit to this issue’s fork.

rishabjasrotia’s picture

Assigned: Unassigned » rishabjasrotia

rishabjasrotia’s picture

Status: Active » Needs review
rishabjasrotia’s picture

smulvih2’s picture

@rishabjasrotia thanks for the MR! I tested this out locally and have the following feedback:

1. I added a new JS file to a library with the new options selected, but no changes were seen when viewing the actual JS file. I had to add the following to library_manager_build_libraries() in library_manager.module:

diff --git a/library_manager.module b/library_manager.module
index ed6fd12..a692cec 100644
--- a/library_manager.module
+++ b/library_manager.module
@@ -117,6 +117,18 @@ function library_manager_build_libraries() {
         // Set header.
         $library_info['header'] = isset($file['header']) && !empty($file['header']) ? TRUE : FALSE;
 
+        // Add custom attributes if they exist.
+        if (isset($file['attributes']) && is_array($file['attributes'])) {
+          foreach ($file['attributes'] as $attribute_name => $attribute_value) {
+            $options['attributes'][$attribute_name] = $attribute_value;
+          }
+        }
+
+        // Set the nomodule attribute to TRUE if it is set.
+        if (!empty($options['attributes']['nomodule'])) {
+          $options['attributes']['nomodule'] = TRUE;
+        }
+
         if ($file['external']) {
           $options['type'] = 'external';
           $library_info['js'][$file['url']] = $options;

After adding the above I get the new attributes displaying correctly in the rendered output.

2. There should be a hook_update to add these new params to all existing library definitions.

New patch attached that addresses both of these points.

  • smulvih2 committed 4e8d02de on 2.0.x
    Issue #3457725: Support for nomodule/module
    
smulvih2’s picture

Status: Needs review » Fixed

This has been merged with the 2.0.x branch and will be included in next release. Thanks for your work on this @rishabjasrotia!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.