Skip to content
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

Differential builds instructions? #3682

Closed
johanalkstal opened this issue Oct 26, 2019 · 8 comments
Closed

Differential builds instructions? #3682

johanalkstal opened this issue Oct 26, 2019 · 8 comments

Comments

@johanalkstal
Copy link

johanalkstal commented Oct 26, 2019

❔ Question

Could we get better docs on how to get differential builds as described in #3011 and https://medium.com/@devongovett/parcel-2-0-0-alpha-1-is-here-8b160c6e3f7e

Using 2.0.0-alpha.2.1.

πŸ”¦ Context

Perhaps I'm not understanding the feature well enough but I've been unable to get something as described to work, where script tags with module and nomodule are automatically created based on targets.

I can get differential builds working by having two different targets in my package.json and running parcel build src/index.html but if I have a single <script module src="main.js"></script> then both will builds will have the module attribute.
If I have two script tags in my index.html, each with module and nomodule attributes then both builds will have the script tags but the src of both tags will point to the same file.

So I don't know how this is supposed to work so that you end up with one version that supports modules and another that doesn't?

@mischnic
Copy link
Member

are automatically created based on targets.

This isn't implemented yet, #3011 would be closed in that case.

If I have two script tags in my index.html, each with module and nomodule attributes then both builds will have the script tags but the src of both tags will point to the same file.

This works for me:

<script type="module" src="index.js"></script>
<script type="text/javascript" nomodule src="index.js"></script>

@johanalkstal
Copy link
Author

are automatically created based on targets.

This isn't implemented yet, #3011 would be closed in that case.

If I have two script tags in my index.html, each with module and nomodule attributes then both builds will have the script tags but the src of both tags will point to the same file.

This works for me:

<script type="module" src="index.js"></script>
<script type="text/javascript" nomodule src="index.js"></script>

What do you mean "it works"?

What I end up with is both pointing to the same file (index.js) which can't be right. The same file can't both support and not support modules.

@johanalkstal
Copy link
Author

We're saying that the module/nomodule feature isn't done yet? But the target builds are? If that's the case then I apologize for my assumptions. I thought they were the same thing.

@mischnic
Copy link
Member

index.html:

<script type="module" src="index.js"></script>
<script type="text/javascript" nomodule src="index.js"></script>

index.js

const x = [1,2,3];
console.log(...x);

Running parcel build index.html generates two javascript bundles with different outputs (one is better optimized).

But the target builds are?

They are rather intended for library builds (module/main/browser), detecting type="module" and nomodule works already, but automatically turning <script type="application/javascript"> into module + nomodule isn't implemented yet.

@johanalkstal
Copy link
Author

I see. type="text/javascript" seems to be the deciding factor here? It needs to exist for this to work?

@mischnic
Copy link
Member

<script type="module" src="index.js"></script>
<script nomodule src="index.js"></script>

Seems to work as well. Which setup have you tried that didn't work?

@johanalkstal
Copy link
Author

Okay I spotted my mistake. I even wrote it in my initial comment.

<script module src="main.js"></script> instead of <script type="module" src="main.js"></script>. πŸ€¦β€β™‚

Sorry for taking your time.

@mischnic
Copy link
Member

πŸ˜„
No worries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants