Skip to content

Commit 361d1a2

Browse files
committed
Added rollup.js to build compile down the code
1 parent da9a56d commit 361d1a2

File tree

7 files changed

+1152
-31
lines changed

7 files changed

+1152
-31
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/node_modules
22
/coverage
3+
/build

.npmignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.DS_Store
2+
node_modules
3+
npm-debug.log
4+
src/
5+
*.test.js
6+
coverage/
7+
rollup.config.js
8+
.gitignore
9+
.prettierrc
10+
jest.config.js

package.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
{
22
"name": "@stackkit/validate",
33
"version": "0.0.1",
4-
"main": "src/validate.js",
4+
"main": "build/index.cjs.js",
5+
"module": "build/index.esm.js",
6+
"browser": "build/index.js",
57
"repository": "[email protected]:stackkit/validate.git",
68
"author": "larsvankleef <[email protected]>",
79
"license": "MIT",
810
"scripts": {
911
"test": "jest --coverage",
1012
"test:watch": "jest --watch",
11-
"test:open": "open coverage/lcov-report/index.html"
13+
"test:open": "open coverage/lcov-report/index.html",
14+
"build": "npx rollup -c"
1215
},
1316
"devDependencies": {
17+
"@rollup/plugin-commonjs": "^14.0.0",
18+
"@rollup/plugin-node-resolve": "^8.4.0",
1419
"jest": "^26.2.2",
15-
"prettier": "^2.0.5"
20+
"prettier": "^2.0.5",
21+
"rollup": "^2.23.1",
22+
"rollup-plugin-filesize": "^9.0.2"
1623
}
1724
}

rollup.config.js

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
import resolve from '@rollup/plugin-node-resolve';
3+
import commonjs from '@rollup/plugin-commonjs';
4+
import filesize from 'rollup-plugin-filesize';
5+
6+
import pkg from './package.json';
7+
8+
const INPUT_FILE_PATH = 'src/index.js';
9+
const OUTPUT_NAME = 'Example';
10+
11+
const PLUGINS = [
12+
resolve({
13+
browser: true,
14+
}),
15+
commonjs(),
16+
filesize(),
17+
];
18+
19+
const OUTPUT_DATA = [
20+
{
21+
file: pkg.browser,
22+
format: 'umd',
23+
},
24+
{
25+
file: pkg.main,
26+
format: 'cjs',
27+
},
28+
{
29+
file: pkg.module,
30+
format: 'es',
31+
},
32+
];
33+
34+
const config = OUTPUT_DATA.map(({ file, format }) => ({
35+
input: INPUT_FILE_PATH,
36+
output: {
37+
file,
38+
format,
39+
name: OUTPUT_NAME,
40+
exports: 'default'
41+
},
42+
plugins: PLUGINS,
43+
}));
44+
45+
export default config;

src/validate.js renamed to src/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
function validate(fields, { rules }) {
22
const checked = []
33

4-
if (!fields || !rules || !rules.fields ) {
4+
if (!fields || !rules || !rules.fields) {
55
return { valid: false, results: [] }
66
}
77

8-
Object.keys(rules.fields).forEach((field) => {
8+
Object.keys(rules.fields).forEach(field => {
99
const value = fields[field]
1010
const rule = rules.fields[field]
1111

src/validation/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@ module.exports = {
3535
email,
3636
length,
3737
number,
38-
required
38+
required,
3939
}

0 commit comments

Comments
 (0)