stealjs / steal-tools

Build easy. Load fast.
https://stealjs.com/docs/steal-tools.html
MIT License
67 stars 23 forks source link

steal-pack-bundles issues #261

Closed wclr closed 8 years ago

wclr commented 9 years ago

@matthewp There is a module that we use to pack bundles after steal build: https://github.com/whitecolor/steal-pack-bundles

1) Please take a look at it and maybe you would have some advice how it can improved and what do you think about the need of such thing.

2) if you clone the repo and run test (npm test) then start some static server to server public folder (that will appear after test build) you will see some erros in the cosole:

Potentially unhandled rejection [2] TypeError: "components/my-component" already exists in the module table
    at c.loader (http://localhost:9000/assets/steal.production-dc661381.js:6:15550)
    at c (http://localhost:9000/assets/steal.production-dc661381.js:6:4589)
    at new b (http://localhost:9000/assets/steal.production-dc661381.js:6:4475)
    at x.define (http://localhost:9000/assets/steal.production-dc661381.js:6:21444)
   ....
steal.production-dc661381.js:6 Potentially unhandled rejection [6] Error loading "components/detached-component" at http://localhost:9000/assets/components/detached-component.js
Error loading "bundles/detached-component-89103bee" at http://localhost:9000/assets/detached-component-89103bee.js
Error evaluating http://localhost:9000/assets/detached-component-89103bee.js
Uncaught TypeError: Module is already loading. (WARNING: non-Error used)

Could you elaborate what they mean?

matthewp commented 9 years ago

Cool, so is the idea of this project to facilitate moving all assets (not just steal but including steal) into a production folder and then updating bundlesPath? I think this is what you're doing.

So probably for this project you would want to be able to prevent steal-tools from writing to the filesystem, right? I'm guessing you clean that up manually. There's actually a way to do this now although it's not completely user-friendly at this point.

Awesome to see projects building on top of steal-tools! I'm guessing this is how you found #260.

As for the error, I'm not sure exactly. Let me pull down your project and test it out.

wclr commented 9 years ago

Yes it would be nice to get rid of fs bundles (it would allow to set correct bundlesPath witch it sould be in production)

The problem currentlty with mode when steal is not bundled in main bundle (packBundle option packSteal: true),

so main module say web/app is turned to web-app-d460f06a

so in index.html in this case:

<script src="/assets/steal.production-dc661381.js" data-main="web-app-d460f06a" data-bundles-path="."></script>

packBundles also adds in the end of file (without it app is not importing)

System.import('package.json!npm').then(function(){
    System.import("web/app");
})

In this case app is loaded normally and works, but in console there is an error, something like:

Potentially unhandled rejection [2] TypeError: "jquery@2.1.4#dist/jquery" already exists in the module table
matthewp commented 9 years ago

Sounds like you have some double-loading going on. I would advise against setting data-main to "web-app-d460f06a". The name of your main is still web/app, the location is just different. You should be updated the bundlesConfig that gets generated. It should be at the top of your main bundle and be System.bundle = { ... }. It's a mapping of each bundle and which modules are included. Your script should look like:

<script src="/assets/steal.production-dc661381.js" data-main="web/app" data-config="package.json!npm" data-bundles-path="."></script>
wclr commented 9 years ago

why data-config="package.json!npm" need to be here? If we have just data-main="web/app" how it is possible to hash it?

matthewp commented 9 years ago

Oh, right. So in this case it might be a race condition happening. Forget my last comment (keep your script tag as it was) and instead change:

System.import('package.json!npm').then(function(){
    System.import("web/app");
})

to:

steal.import("web/app");

This should wait for the bundle to be loaded. Let me know.

wclr commented 9 years ago

Well that works the same way. App is loaded but the same errors in console are in place.

matthewp commented 9 years ago

Arg, then it's not the issue i would have thought. So I can test this by pulling down your project and running npm test? I'll take a look later if so.

wclr commented 9 years ago

Yes if you run npm install then npm test (mocha is needed globally) it will build the app in public, that run some static server (for example harpjs.com - harp server public and access localhost:9000) in console you should see the errors and strange behaviour that detached-module is loaded twice.

wclr commented 9 years ago

@matthewp I've updated https://github.com/whitecolor/steal-pack-bundles#tests instructions, so you can eseally navigate throught there result and see the errors in console (packed and built version have them) And modules are imported twice (I belive there is a problem with global modules)

wclr commented 9 years ago

Haven't you tried?

matthewp commented 9 years ago

I just did, I do not get errors when looking at /packed/index.html but I do see the double loading. That's caused because there is only 1 define in the bundle, so we should be able to fix that. Please file that in stealjs/steal, want to keep the issues separated and concise.

wclr commented 9 years ago

Well I think this error are due double loading.