-
Notifications
You must be signed in to change notification settings - Fork 471
Add universal module definition support (related to issue #329) #395
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
Add universal module definition support (related to issue #329) #395
Conversation
-Add prepublish script and .npmignore so prod files are always present before publishing (not necessary now since prod files are in the repo, but would be necessary if prod files are not kept in source control) -Add UMD task to add universal module definition boilerplate to main files (better support for AMD and CommonJS-like environments) It seems to work fine with Browserify (excluding add-on validation modules) and with require.js. However -- extra modules very likely won't work with Browserify out of the box. Users would have to transfer those files to the same directory the rest of the JS is in.
with this change the user should be able to require the form validator tool before jQuery, and there should be no need to explicitly add $ or jQuery as global variables.
Add universal module definition support (related to issue #329)
Great! Hm.. Doesn't browserify use the scripts located in |
The production files will probably be kept in source control. For two reasons:
|
I think cdnjs can be configured to auto-update from npm (https://github.com/cdnjs/cdnjs/blob/master/documents/autoupdate.md). |
What Browserify does is bundle all of the Javascript into one big file. Wherever the user puts that one big file is where (I think) the form validator tool would think is its base directory, and it would look in that same directory for the modules. The thing is, the whole point of Browserify is stick all Javascript together to minimize the number of server requests, which is almost the opposite of the module approach. If I was using Browserify, I would prefer to have the modules I was using concatted with the main validator file, so that there was no need for extra server requests later on. To make that happen, I was thinking there could be some kind of installation options so the user could select the modules she was using at the time the form validator tool was downloaded. |
What do you mean by installation options? Wouldn't the ideal situation, for the end-programmer, be to require each validation-module that she wants in the bundle? Something like require('jquery-form-validator');
require('jquery-form-validator-security');
require('jquery-form-validator-date'); What is required if we want to support this? Each module having its own repository that gets published to npm? |
I was thinking the installation options would be some flags used to decided which modules were included in the form-validator (like 'date, file'). Then when the form validator was required, it would automatically have those modules in it. I like the approach you gave, where each of the modules is required separately -- that seems much more straightforward. I will research what we have to do to support that. I think it'd be extra overhead to have multiple node modules (even if we write a script to automate it) so I'd want to avoid that. |
I read this thread on so http://stackoverflow.com/questions/25784463/browserify-including-entire-module-when-only-some-parts-used-react-addons If I have understood it correctly this won't be an issue. It will look something like this: require('jquery-form-validator/security'); I will try it out later tonight, |
Cool, that was the first thing I was thinking of trying. I was hoping On 3/4/16, Victor Jonsson notifications@github.com wrote:
|
The modules also need to be UMD wrapped. This works: require('jquery-form-validator/form-validator/security.js'); assuming jQuery / $ are already global variables. |
-Add prepublish script and .npmignore so prod files are always present before publishing (not necessary now since prod files are in the repo, but would be necessary if prod files are not kept in source control); this also ensures the latest version is always built/tested/minified before publishing on npm
-Add universal module definition task to add boilerplate to main files (better support for AMD and CommonJS-like environments)
This seems to work fine with Browserify (excluding add-on validation modules) and with require.js.
However, extra modules very likely won't work with Browserify out of the box. Users would have to transfer those files to the same directory the rest of the JS is in.