Skip to content

Commit

Permalink
Add universal module definition support
Browse files Browse the repository at this point in the history
-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.
  • Loading branch information
ray-print committed Feb 29, 2016
1 parent ba2ba34 commit d5da2f9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
10 changes: 10 additions & 0 deletions .npmignore
@@ -0,0 +1,10 @@
#Testing, not relevant to end user
test/
.travis.yml
.jshintrc

#Not relevant to npm users
bower.json

#IDE
.idea/
35 changes: 28 additions & 7 deletions Gruntfile.js
@@ -1,7 +1,7 @@
//TODO: During next major version bump change to /dist. Leaving at ./form-validator for backwards
//compatibility
const DIST_DIR = './form-validator';
const MAIN_PLUGIN_FILE = './form-validator/jquery.form-validator.js';
const MAIN_PLUGIN_FILE = './form-validator/jquery.form-validator';
const SRC_DIR = './src';
const MAIN_DIR = '/main/';
const MODULE_DIR = '/modules/';
Expand Down Expand Up @@ -79,7 +79,25 @@ function initializeGruntConfig(grunt, filesToBuild) {
}
},

clean: [DIST_DIR + '/']
clean: [DIST_DIR + '/'],
umd: {
main: {
options: {
src: MAIN_PLUGIN_FILE + '.js',
deps: {
'default': ['$']
}
}
},
minified: {
options: {
src: MAIN_PLUGIN_FILE + '.min.js',
deps: {
'default': ['$']
}
}
}
}
});
}

Expand All @@ -89,7 +107,7 @@ module.exports = function (grunt) {
concat: {
main:{
src: [SRC_DIR + MAIN_DIR+'core-validators.js'],
dest: MAIN_PLUGIN_FILE
dest: MAIN_PLUGIN_FILE + '.js'
}
}
};
Expand Down Expand Up @@ -140,8 +158,8 @@ module.exports = function (grunt) {
};

// Add main script to uglify
filesToBuild.uglify[MAIN_PLUGIN_FILE] = {
src: MAIN_PLUGIN_FILE,
filesToBuild.uglify[MAIN_PLUGIN_FILE + '.js'] = {
src: MAIN_PLUGIN_FILE + '.js',
expand: true,
extDot: 'last',
ext: '.min.js'
Expand Down Expand Up @@ -183,7 +201,10 @@ module.exports = function (grunt) {
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.registerTask("build-production", ["version", "cssmin", "test", "uglify"]);
grunt.registerTask('test', ['concat', 'cssmin','jshint', 'qunit']);
grunt.loadNpmTasks('grunt-umd');

grunt.registerTask("build-production", ["version", "test", "uglify"]);
grunt.registerTask('test', ['concat', 'umd', 'cssmin','jshint', 'qunit']);
grunt.registerTask("default", ["test", "watch"]);
grunt.registerTask("prepublish", ["test", "uglify"]);
};
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -13,7 +13,7 @@
"url": "git+https://github.com/victorjonsson/jQuery-Form-Validator.git"
},
"bugs": {
"url": "https://github.com/jquery-boilerplate/jquery-boilerplate/issues"
"url": "https://github.com/victorjonsson/jQuery-Form-Validator/issues"
},
"author": {
"name": "Victor Jonsson",
Expand All @@ -33,6 +33,7 @@
"grunt-contrib-qunit": "^0.7.0",
"grunt-contrib-uglify": "~0.11.1",
"grunt-contrib-watch": "^0.6.1",
"grunt-umd": "~2.3.5",
"jquery": "^2.1.4",
"numeral": "~1.5.3",
"qunitjs": "^1.20.0"
Expand All @@ -41,6 +42,7 @@
"jquery": ">1.8.0"
},
"scripts": {
"prepublish": "grunt prepublish",
"test": "grunt test"
}
}

0 comments on commit d5da2f9

Please sign in to comment.