Commit cf1c2a9
committed
WebPack Loader Script Modules Support
Since the `ScriptModule` has been integrated, we can register WP modules, but only when we create the Assets programmatically. There's no support for modules within the Autoloader.
These changes aim to support modules by establishing a module filename convention as `.mjs` might not work correctly if it isn't possible to guarantee the server is serving the mjs resources with the correct MIME type.
Hence, a `.module.js` seems to be a good tradeoff and the number of changes necessary to make it work ar limited, so in the future when (and if) the `mjs` are well-supported, we can slightly improve the solution.
The changes involve two key points
- The `AbstractWebpackLoader` so that the class can recognize the new `ScriptModule` class as an instantiable class for those files ending with `.module.js`.
- The `WebpackManifestLoader` to correctly use the original `handle` rather than the file name. WordPress Modules start with `@` though, not required it is an established convention and would make sense to keep the handle provided by the manifest rather than guessing it by the file name.
Note:
The Manifest file contains a key value pair, and it could be possible to extract the handle from the key, which might be a file path in the classic case the webpack plugin is configured with `basePath: './'` and `publicPath: './'`. I would not suggest changing the approach here and with these changes as it would be comparable to a breaking change, while the current ones can be seen as a minor change because, the file name ending with `.module.js` would trigger the registration using the `ScriptModule`.1 parent b328f2f commit cf1c2a9
2 files changed
Lines changed: 17 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
110 | 111 | | |
111 | 112 | | |
112 | 113 | | |
| 114 | + | |
113 | 115 | | |
114 | 116 | | |
115 | 117 | | |
116 | 118 | | |
| 119 | + | |
117 | 120 | | |
118 | 121 | | |
119 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
120 | 127 | | |
121 | 128 | | |
122 | 129 | | |
123 | 130 | | |
124 | 131 | | |
125 | 132 | | |
126 | | - | |
| 133 | + | |
127 | 134 | | |
128 | 135 | | |
129 | 136 | | |
| |||
137 | 144 | | |
138 | 145 | | |
139 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
140 | 152 | | |
141 | 153 | | |
142 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | | - | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
| |||
0 commit comments