-
Notifications
You must be signed in to change notification settings - Fork 27
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
Questions #1
Comments
Thanks @Shepless for the compliments. 😄 I think what I hear you saying is that you'd like to provide 3rd party modules (aka: components) for people to use in their own projects. What I would do is package them up so that they look like an npm module, which is to say that everything that is needed is contained in a single folder and then publish that somehow (I say somehow in that I don't know if you want these modules to be public or not). I have a slight example of what I think you're talking about in the todo example. Specifically, I'm depending on the third party TodoMVC css files. SystemJS just allows those to be imported as modules. In this case, it is just CSS, but it could be anything else you'd like, including angular modules or Less/Sass. There is also a really neat 'hack' in systemjs-seed in that there is a routing.js module which combines SystemJS with ui-router futurestates and ocLazyLoad. This enables the app to dynamically load things at runtime based on route. Let me know if you'd like more examples or clarification. |
@lookfirst No problem, I really appreciate you getting back so quickly! You're exactly right about the approach. I would probably be looking to publish them to github so people can install via The todo example is close to what I am looking for, but I'm not sure if its exactly the same - Rather than have the CSS in a separate module I would want to publish all assets together, for example ModuleA: build-output So if I were a consumer of this as dependency it would be nice if I could do something like (for the LESS compilation): gulp.task('build', function () {
return gulp.src('./jspm_packages/modules/**/*.less')
// ...
}); Not sure if that is possible or even the best approach? Would you always recommend pre-compiling the LESS to CSS for the build output of a module? On top of this I'm not sure how the pre-compilation of templates fits into the picture in terms of imports, since in dev mode they would probably stay as .html files but in production they would be .js files and I would imagine SystemJS would no longer find the module. Apologies for the all the questions! |
No worries, questions are good. 👍
So, for example, let's say that directive-a.js depends on a template and some css. You'd structure it just like I've done with the todo example where I've declared the template and css dependencies directly in the todo.js file. When you import this module into another project, all that project has to do is depend on the import path, which is all setup automatically in the system.config.js. I'm currently working on a yeoman generator that outputs the same gulpfile as this project already has. That way, you can create re-usable module projects more easily. If this still isn't clear, I'll build an example of what I'm talking about soon. |
Play with this seed project a bit and try to get a feeling for how all the bits fit together. I think it will help lift the fog of how everything fits together a bit. It took me a while myself, but hopefully this project makes it more clear. |
Excellent, I play around some more. The example would be fantastic if you get the opportunity. When I've (hopefully!) made some progress I'll let you know so you can pick it apart haha! Thanks again for all your help - I really appreciate it! |
I've been looking through the project and I have noticed that you aren't using the SystemJS Builder module to build your scripts. I would have thought that this would be needed? |
It is used, but only for 'production' mode and it is used through this project: https://github.com/Swimlane/systemjs-route-bundler |
Ah ha! Thanks again 😄 |
Ok, yeoman generator is done for now. Can you give me an example self-contained component that you'd like to build? I'll fit it into my stuff and show you what can be done. |
@lookfirst that was fast! I have a WIP test module that I'm working on here I know you said that the nested directory structure wasn't required, but if I'm being honest I like the structure so I kept it 😄 This is by no means the finished article but gives you a good idea of what I'm trying to achieve. I think it's almost there, the only stumbling block is if I use the jspm cli to bundle-sfx it fails, still looking into why. Let me know what you think. |
Ok, I've 'rewritten' your code to fit under my semi-opinionated way of doing things. https://github.com/lookfirst/module-a What I did was:
Things to note:
|
Apologies for the delay - I've just got in from work so will take a look at this tonight. Thanks for all the effort. |
Immediate thoughts are:
I'll keep playing around, but thanks again! |
|
Awesome stuff. The second point is a personal preference but it also has practical thought behind it, which is that angular modules aren't the best and can be easily overwritten by other modules so minimising them reduces the chances of clashes. |
always namespace your modules. you can use so, it becomes:
which resolves at runtime to the name of the file.
|
Great work @lookfirst ! I'll piggyback on here for now, where are your watcher tasks located now? In my fork of the original project, I broke out separate subroutines and watchers for LESS vs other assets in watch / compile because the LESS file changes were triggering full-page refresh, which for me defeats the purpose of browserSync. Also, when I cloned this project just now and added a |
When I have 20 projects, I'd much rather have a single place for all those tasks rather than having to fix 20 projects when one of those tasks goes wrong. In fact, this is a perfect example, you found a bug! Now I update my gulp-helpers and every project down the chain gets the fix without having to modify their gulpfile at all. With regards to dependencies getting out of date, I'm ok with that cause I'm just more concerned with repeatable builds. You'll know right away from your CI system if something breaks. If you want to contribute, I'll give you commit access and I have years worth of responding to PR's in a timely fashion across many projects. You can also always fork the project and use the fork instead. I ❤️ github. This is the less task: https://github.com/lookfirst/gulp-helpers/blob/master/src/tasks/less.js Interesting, it was actually a bug that I picked up from the parent project: https://github.com/Swimlane/angular-systemjs-seed/blob/master/gulpfile.js#L107
https://github.com/sindresorhus/gulp-changed#extension I just pushed v1.2.3 to npm. Enjoy. 😄 |
So, the interesting thing is that this started from this discussion: lookfirst/systemjs-seed#1 (comment) I suggest that you adopt [gulp-helpers](https://github.com/lookfirst/gulp-helpers). It was based off this gulpfile and would really help clean up a lot of your code.
I tend to agree with @lookfirst on this one. On the subject of dependencies - surely this approach is better as it allows you to manage to them in one place? Meaning that you can't get any kind of version mis-matches between projects (especially important if they interact in some way), it gives you far more control over management I think. I will definitely be using either the repo already available or look into building my own. |
If you build your own, let me know! I know that gulp-helpers is just one way of doing it. I'm always interested in seeing other ideas. 😄 |
I'm going to close this as I think the discussion has ended. =) If you have further questions, feel free to open new issues! |
@lookfirst First off, thanks for taking the time and effort to produce such a comprehensive example! I am looking at using JSPM and SystemJS to build a library of separate and re-usable modules. These SystemJS modules will export angular services/controllers/directives along with templates and CSS or LESS.
My main concerns are how I would expose the JS, LESS or CSS (or which I would expose?) and pre-compiled HTML templates for a consuming project in one go and also how the consuming project would be able to handle loading these in a development/production environment.
As an example lets say I have
ModuleA
andModuleB
as separate SystemJS modules and each contain an angular directive, a corresponding HTML template and LESS styling. If I am buildingMyProject
that has dependencies on these two modules how would it build all of the styling and pre-compile the templates in a dev and production environment? Ideally I would like people to be able to build the dependencies in isolation (e.g. "vendors.min.js" and "vendors.min.css") and build their own "my-project.min.js" files that depend on it. I've seen examples of people using the SystemJS builder in a gulp build system but not to load inModuleA
andModuleB
LESS files to compile and concat. They only seem to build individual files that are isolated to their SystemJS modules.I hope that makes sense and that you might have suggestions as you are clearly far more versed in JSPM and SystemJS than I. I am still in the early learning phase of these two technologies.
Any help/advice is greatly appreciated.
The text was updated successfully, but these errors were encountered: