Answer the question
In order to leave comments, you need to log in
Building a project, AMD, LMD, using project modules
I'm not great at building JavaScript projects, for me it usually came down to using file concatenation / minification in grunt.js. And here I had to think about what and how to do.
Actually I am writing now in my free time one library (for use in the browser). The library consists of modules, if necessary, in the library settings, some modules can be replaced by others. At first I wanted to use require.js or any other module manager for these purposes. But again, there was a problem behind the assembly of the library.
Each module is small in itself, averaging around 150 lines. There are currently 20 modules, half can be replaced with your own. The names of the modules used are described in the library settings, and then through the module manager (self-written, the require.js API was copied for compatibility). Again, I really don’t want to drag require.js or any other similar library, I don’t want extra dependencies.
Each module is wrapped with a define function and exports one module. Again, there is a desire to squeeze the whole thing as much as possible. That is, when building, you need to combine all exports into one and enclose the whole thing in one define or each logical part (core, components, ui) in your define.
Does this make sense, has anyone come across projects where such an assembly is implemented, or should I think in a different direction?
Answer the question
In order to leave comments, you need to log in
Using assembly and automation is definitely worth it.
require.js has its own module builder and optimizer - r.js I
worked with it quite a lot from experience, I can say that it is good, but it didn’t suit me - it’s a chore to maintain a project on it:
- this is AMD, which means you need to write a define wrapper, to cast spells if you want to use a module in node.js ... (you can not write a wrapper, but you will have to cast spells again)
- require () - God Object and returns all kinds of resource types in all kinds of ways. It takes a long time to delve into what’s what if the code is someone else’s
- its plugin system is strange for perception “from scratch”
- the result of the assembly is difficult to look at “everything is somehow itself”
In general, I got tired of AMD and RequireJS, looked towards all sorts of similar projects, because I didn’t want to write another bike. As a result, I had to write the tool of my dreams - LMD.
I proceeded from the following considerations:
* Today everything is going. Even dev
- why write a wrapper and just write something extra if a robot can do it for you ?!
* Code readability is very important
- It is necessary to exclude implicit constructions
- As an architect of my project, I want to know what will be “rolling” in it
* There are many assemblies
- dev, production, dev-ru, test-en_US
* Need to control the result of the assembly
- Integrity check
- Assembly details
— Analytics
Today, LMD can do everything that other builders can, and has a number of advantages: CommonJS / Modules, honest and total isolation of modules, smart build analytics, both static and dynamic, CLI with autocomplete, GUI. LMD is especially good if you have many builds - many languages, many environments.
If you are using grunt, then LMD has a plugin for it - grunt-lmd .
Literally, I wrote a whole bunch of examples for all kinds of plugins and LMD features. Check them out. If you have any questions ask here or in the PM.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question