-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Parse entry point of index.html and rewrite JS for serverless injection #58
Comments
As part of the build step, I sort of feel like the best approach will be to use node to parse the HTML using JSDOM something like this: const filePath = path.resolve(__dirname, `${theIndex.html}`)
const readInterface = readline.createInterface({
input: fs.createReadStream(`${filePath}`),
terminal: false
})
readInterface.forEach((line) => {
const { document } = (new JSDOM(line)).window
let el = document.querySelector('script')
...
}).catch(e => {
console.log(e)
}).finally(() => {
// magick
}) But obviously readLIne won't work all the time, so its just a preliminary sketch. |
Well, maybe the approach we can use to make the monolith here is to mung the index.html, looking for JS files and just directly inlining them. Whether or not we'd need to actually destructure dynamicImports is something to look at too. |
We are making some progress on the feature/iframe branch, it might be the best solution. |
@lucasfernog - I think that the merge of features/no-server resolves this. |
Is your feature request related to a problem? Please describe.
The problem is that different frameworks use different strategies for JS injection in the root app. In the serverless distribution type, we need to do some slight transformation to the JS in order to properly inject it.
Describe the solution you'd like
At build time (not dev because that is really served via webpack) we need to parse the source of the index.html for JS and transform the JS for injection. On a sidenote, this is also where we can inject the CSP meta value.
Describe alternatives you've considered
There are a couple of alternatives:
Additional context
In an earlier iteration I hand-crafted the entry file and totally ignored the index.html file that was shipping. Here is the example:
The text was updated successfully, but these errors were encountered: