Skip to content

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

Merged

Conversation

ray-print
Copy link
Contributor

-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.

-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.
victorjonsson added a commit that referenced this pull request Feb 29, 2016
Add universal module definition support (related to issue #329)
@victorjonsson victorjonsson merged commit 3996b62 into victorjonsson:master Feb 29, 2016
@victorjonsson
Copy link
Owner

Great!

Hm.. Doesn't browserify use the scripts located in form-validator?

@victorjonsson
Copy link
Owner

The production files will probably be kept in source control. For two reasons:

  1. cdnjs pulls latest tag from the repository to the CDN host.
  2. The novice web hacker (which are the main audience for this plugin) doesn't necessarily know how to use any build tools. They need a simple download-and-you're-set-to-go approach.

@ray-print
Copy link
Contributor Author

I think cdnjs can be configured to auto-update from npm (https://github.com/cdnjs/cdnjs/blob/master/documents/autoupdate.md).
It's more intuitive to download a file and then use that file, I agree. At this point there are several easy alternatives -- using bower or npm, or just pulling the file directly from cdnjs (which is what I did when I used this library for the first time) -- but you're right, for maximum accessibility it's good to have it be available as a simple download.

@ray-print ray-print deleted the 160228/addUMDBoilerplate branch February 29, 2016 18:52
@ray-print
Copy link
Contributor Author

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.

@victorjonsson
Copy link
Owner

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?

@ray-print
Copy link
Contributor Author

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.

@victorjonsson
Copy link
Owner

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,

@ray-print
Copy link
Contributor Author

Cool, that was the first thing I was thinking of trying. I was hoping
that would work but wasn't optimistic. (I've been wrapped up in other
projects lately.)

On 3/4/16, Victor Jonsson notifications@github.com wrote:

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 should simply
work to do something like:

require('jquery-form-validator/security');

I will try it out later tonight,


Reply to this email directly or view it on GitHub:
#395 (comment)

@ray-print
Copy link
Contributor Author

The modules also need to be UMD wrapped. This works:

require('jquery-form-validator/form-validator/security.js');

assuming jQuery / $ are already global variables.
I'll add the modules to the UMD task, should have time in the next couple days.
It'd be slightly nicer to have the require names be 'jquery-form-validator/modules/security' and 'jquery-form-validator/lang/de' (vs. 'jquery-form-validator/form-validator/lang/de') but I don't see a way to do that without changing the directory structure/breaking existing functionality (too bad symlinks don't work on Windows :( ...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants