Bundling with Rollup

This guide is outdated and should be used for FormValidation v1.x.x only. From v2.0.0, FormValidation is available as npm packages and it can be bundled with Rollup like other npm packages.
FormValidation was rewritten in ES6 from v1.0.0. It comes with the @form-validation/cjs directory that consists of ES6 compatible classes. This guide shows how you can bundle FormValidation with Rollup.
Assume that your folder has the following structure:
the-root-directory
|
├── node_modules
├── vendors
| └── @form-validation
| └── cjs
└── rollup.config.js
Now, you can set the alias to FormValidation by installing the @rollup/plugin-alias plugin:
// Run this command from the root directory
$ npm install @rollup/plugin-alias --save-dev
and using it in rollup.config.js:
// rollup.config.js
import alias from '@rollup/plugin-alias';
const path = require('path');
module.exports = {
plugins: [
alias({
entries: [
{
find: '@form-validation',
replacement: path.resolve(__dirname, 'vendors/@form-validation/cjs'),
},
],
}),
],
};
From now on, you can import any file from FormValidation cjs package as following:
// Use the algorithms
import { algorithms } from '@form-validation/core';
// Use the validators
import { creditCard } from '@formv-alidation/validator-credit-card';
const result = creditCard().validate({
value: ...,
options: {
message: ...,
},
});
// Use the core library
import { formValidation } from '@form-validation/bundle/popular';
// Use the plugins
import { Icon } from '@form-validation/plugin-icon';
import { Trigger } from '@form-validation/plugin-trigger';
import { Bootstrap } from '@form-validation/plugin-bootstrap';
...

See also