emscripten-core / emscripten-core/emscripten
How could I read a '-s' option in file_packager.py?
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 105
Description
There's a omission in `file_packager.py` with `-s EXPORT_ES6` is that:
when you are using ES6 import, the position of preload file - `.data` will be depend on the position of main js script. so the url calculation logic should be changed from:
```javascript
var REMOTE_PACKAGE_NAME = Module['locateFile'] ? Module['locateFile'](REMOTE_PACKAGE_BASE, '') : REMOTE_PACKAGE_BASE;
```
to:
```python
'''
...other
var REMOTE_PACKAGE_NAME;
if (Module['locateFile']) {
REMOTE_PACKAGE_NAME = Module['locateFile'](REMOTE_PACKAGE_BASE, '')
} else {
'''
if EXPORT_ES6:
ret += '''
REMOTE_PACKAGE_NAME = new URL("%s", import.meta.url).toString();
''' % (shared.JS.escape_for_js_string(data_target))
else:
ret += '''
REMOTE_PACKAGE_NAME = REMOTE_PACKAGE_BASE;
'''
ret += '''
}
...other
'''
```
Contributor guide
Assessment
This issue has not been assessed yet.