-
Notifications
You must be signed in to change notification settings - Fork 28
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
Allow imported scripts to load as modules #1054
Comments
I'm wondering how this would work....I'm guessing we'd need to add a checkbox next to a the URL to specify if the script is a module? |
An example: // index.html
<script type="module" src="./module.js"></script> // module.js
import { print } from './printer.js';
globalThis.Print = print; // printer.js
export function print(name) {
console.log(name);
} // pc.ScriptType
var Script = pc.createScript('script');
Script.prototype.initialize = function() {
Print('example');
}; |
This will definitely break if enabled by default for all scripts. So this should be an option for individual scripts. |
A good example that users have run into is the firebase SDK https://forum.playcanvas.com/t/uncaught-syntaxerror-cannot-use-import-statement-outside-a-module/23242/ |
Adding We are gradually moving toward first class support for ES modules in the engine and editor, so the above use case can be solved like this; // printer.js
export function print(name) {
console.log(name);
} import { print } from './printer.js';
// pc.ScriptType
var Script = pc.createScript('script');
Script.prototype.initialize = function() {
print('example');
}; Closing for now as unplanned |
This is a feature request to allow third party scripts to be loaded as module.
![image](https://private-user-images.githubusercontent.com/5677782/263501608-dbd77561-3a81-4d56-a2e0-9f25e44cd071.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzQ1OTkzODMsIm5iZiI6MTczNDU5OTA4MywicGF0aCI6Ii81Njc3NzgyLzI2MzUwMTYwOC1kYmQ3NzU2MS0zYTgxLTRkNTYtYTJlMC05ZjI1ZTQ0Y2QwNzEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MTIxOSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDEyMTlUMDkwNDQzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTk2NGIyNDJkOWEwODdlMDAzNDFiOGNiNmU2OWM5MGRiY2ViOTVlYjQ0NWU3MmJjOGFkZDcyMDhjNTljMzQ1ZSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.P7egQiB9dsW0eUk5GrD4eZf4sg48wLNje-F6y5EZFUY)
would become
The text was updated successfully, but these errors were encountered: