Skip to content

Commit d5da2f9

Browse files
committed
Add universal module definition support
-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.
1 parent ba2ba34 commit d5da2f9

File tree

3 files changed

+41
-8
lines changed

3 files changed

+41
-8
lines changed

.npmignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#Testing, not relevant to end user
2+
test/
3+
.travis.yml
4+
.jshintrc
5+
6+
#Not relevant to npm users
7+
bower.json
8+
9+
#IDE
10+
.idea/

Gruntfile.js

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//TODO: During next major version bump change to /dist. Leaving at ./form-validator for backwards
22
//compatibility
33
const DIST_DIR = './form-validator';
4-
const MAIN_PLUGIN_FILE = './form-validator/jquery.form-validator.js';
4+
const MAIN_PLUGIN_FILE = './form-validator/jquery.form-validator';
55
const SRC_DIR = './src';
66
const MAIN_DIR = '/main/';
77
const MODULE_DIR = '/modules/';
@@ -79,7 +79,25 @@ function initializeGruntConfig(grunt, filesToBuild) {
7979
}
8080
},
8181

82-
clean: [DIST_DIR + '/']
82+
clean: [DIST_DIR + '/'],
83+
umd: {
84+
main: {
85+
options: {
86+
src: MAIN_PLUGIN_FILE + '.js',
87+
deps: {
88+
'default': ['$']
89+
}
90+
}
91+
},
92+
minified: {
93+
options: {
94+
src: MAIN_PLUGIN_FILE + '.min.js',
95+
deps: {
96+
'default': ['$']
97+
}
98+
}
99+
}
100+
}
83101
});
84102
}
85103

@@ -89,7 +107,7 @@ module.exports = function (grunt) {
89107
concat: {
90108
main:{
91109
src: [SRC_DIR + MAIN_DIR+'core-validators.js'],
92-
dest: MAIN_PLUGIN_FILE
110+
dest: MAIN_PLUGIN_FILE + '.js'
93111
}
94112
}
95113
};
@@ -140,8 +158,8 @@ module.exports = function (grunt) {
140158
};
141159

142160
// Add main script to uglify
143-
filesToBuild.uglify[MAIN_PLUGIN_FILE] = {
144-
src: MAIN_PLUGIN_FILE,
161+
filesToBuild.uglify[MAIN_PLUGIN_FILE + '.js'] = {
162+
src: MAIN_PLUGIN_FILE + '.js',
145163
expand: true,
146164
extDot: 'last',
147165
ext: '.min.js'
@@ -183,7 +201,10 @@ module.exports = function (grunt) {
183201
grunt.loadNpmTasks('grunt-contrib-connect');
184202
grunt.loadNpmTasks('grunt-contrib-qunit');
185203
grunt.loadNpmTasks('grunt-contrib-cssmin');
186-
grunt.registerTask("build-production", ["version", "cssmin", "test", "uglify"]);
187-
grunt.registerTask('test', ['concat', 'cssmin','jshint', 'qunit']);
204+
grunt.loadNpmTasks('grunt-umd');
205+
206+
grunt.registerTask("build-production", ["version", "test", "uglify"]);
207+
grunt.registerTask('test', ['concat', 'umd', 'cssmin','jshint', 'qunit']);
188208
grunt.registerTask("default", ["test", "watch"]);
209+
grunt.registerTask("prepublish", ["test", "uglify"]);
189210
};

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"url": "git+https://github.com/victorjonsson/jQuery-Form-Validator.git"
1414
},
1515
"bugs": {
16-
"url": "https://github.com/jquery-boilerplate/jquery-boilerplate/issues"
16+
"url": "https://github.com/victorjonsson/jQuery-Form-Validator/issues"
1717
},
1818
"author": {
1919
"name": "Victor Jonsson",
@@ -33,6 +33,7 @@
3333
"grunt-contrib-qunit": "^0.7.0",
3434
"grunt-contrib-uglify": "~0.11.1",
3535
"grunt-contrib-watch": "^0.6.1",
36+
"grunt-umd": "~2.3.5",
3637
"jquery": "^2.1.4",
3738
"numeral": "~1.5.3",
3839
"qunitjs": "^1.20.0"
@@ -41,6 +42,7 @@
4142
"jquery": ">1.8.0"
4243
},
4344
"scripts": {
45+
"prepublish": "grunt prepublish",
4446
"test": "grunt test"
4547
}
4648
}

0 commit comments

Comments
 (0)