Closed IngwiePhoenix closed 9 years ago
Can you use webpack to keep track of the dependency tree for all .oj files, and then pass the concatenated version to ojc when any of them change?
Sadly not. All I can do is create the list of files myself. The way it works can be seen here:
The resulting file is actually a combined version of all files together, the require() call being replaced with an internal loader. So the build itself is dynamic. Currently, the online version of my demo uses UglifyJS to press down the size of the script. Otherwise I could’ve shown you. :)
The process is, that WebPack first sets up it’s own version of a require() function plus resolver. The resolver is aware that .oj files should be processed with my loader. The loader gets the source, processes it to plain JavaScript and passes that source - and eventually plus a source map - back. The JavaScript is then added to the webpack - and when the pack is run, the code acts as if it was require()’d. In my case, I use a .oj file directly as the entry, and am working on an application class. This whole setup is still very new, but I am planning to develop a front-end library using OJ that is based off jQuery, so i can merge commonly used functions in my app - such as emitting events to socket.io - into a single, simple interface.
Therefore, I have to either build the file list on my own, or I have to find another way. WebPack provides a file watcher interface, that can re-compile my bundle on-demand. So if I publish a code change, it can re-create the bundle right away.
I managed to fix my issue with the compilation. The current oj-loader
works veeeery flawlessly. And as far as I know, ti is the ONLY "Objective-X" loader that there is. ObjJ still struggles with a NodeJS port, while I already have this working just fine. :)
I just realized, that I have an issue in my loader for WebPack: When the file is changed and re-compiled, my loader returns an internally cached source, thus otherwise re-using the existing compiler-cache... So even if I update my file, the changes are not reflected unless I force-reload the module, thus whiping the internal cache and forcing a fresh rebuild.
Since I want to allow the
squeeze
option, I thought I should keep the compiler state, and return a pre-cached version...guess this method does not quite work. Can you recommend an alternative way to go about this?https://github.com/IngwiePhoenix/oj-loader/blob/master/index.js#L28-32