choojs / bankai

:station: - friendly web compiler
Apache License 2.0
1.09k stars 102 forks source link

🐛: no access to process.env variables using `bankai start` #503

Closed austinfrey closed 6 years ago

austinfrey commented 6 years ago

Expected Behavior

When using bankai start there should be a number of process.env variables available i.e. FILE_LIST

Current Behavior

When using bankai start for development, process.env variables (i.e. process.env.FILE_LIST) are unavailable.

i.e. when trying to load a service worker, files are not cached since the process.env.FILE_LIST is undefined

Uncaught (in promise) TypeError: Failed to execute 'addAll' on 'Cache': The provided value cannot be converted to a sequence.

Possible Solution

from @goto-bus-stop on irc. "we should instead manually add 'envify' during bankai start, like is done for the other JS files"

Context

I'd like to be able to load a service worker in development using bankai start vs needing to perform bankai build

Code Sample

Your Environment

Software Version(s)
Package bankai 9.14.0
Runtime node v8.11.1
Package Manager npm
Operating System Ubuntu
austinfrey commented 6 years ago

I'd also add that in order to work offline, I think the service-worker also needs to cache the '/' directory and the 'index.html' file to work offline. I just added URLS.push('/', 'index.html') to my service worker and it was fine. Is that something that should be included or do others handle it differently?

edit: this is not an issue. index.html will be cached automatically

ZhouHansen commented 6 years ago

Based on my understanding, service-worker is used for production mode, and check https://github.com/facebook/create-react-app/issues/2396 : "It is intentional. Using a service worker in development can lead to extremely confusing debugging situations." Why you need to use it on the dev mode?

ZhouHansen commented 6 years ago

In your case, if service-worker didn't cache '/' and 'index.html', your app will not be load offline, right?

austinfrey commented 6 years ago

@ZhouHansen thanks for the feedback and I can see what you mean. I was hoping to be able to test the service-worker's capabilities locally and as I make changes. Aside from the service-worker use case, there could be other reasons/use-cases that having those variables present could be useful for development.

I'll add that my second comment about manually adding the index.html file is not necessary. For some reason my index.html file was not being created when running the build step so it was not listed in process.env.FILE_LIST and thus, not cached, but it seems to have resolved itself and is now generating, so that's not an issue anymore.

ZhouHansen commented 6 years ago

Bankai transforms kinds of assets (html, javascript, style, image..), then output them as bundles. Some transform processes of these assets dependent on others, e.g. the html transform process can only start after javascript files have been transformed. And the transform process of service-worker dependent on all rest of transform process, because the FILE_LIST can only be generated after all rest of transforms finish. You can't access FILE_LIST from such as bundle.js, for now it is only accessible from service-worker. If you get a detailed use case for use FILE_LIST. Please let us know.

austinfrey commented 6 years ago

@ZhouHansen appreciate the explanation :) . I'll go ahead and close, since I have a work-around that works well enough.