Skip to content

Commit cf493b8

Browse files
authored
Merge pull request #20 from environment-agency-austria/chore/migrate-to-rollup
Chore/migrate to rollup
2 parents 10a9179 + fb2a990 commit cf493b8

File tree

12 files changed

+525
-3404
lines changed

12 files changed

+525
-3404
lines changed

.babelrc

Lines changed: 0 additions & 7 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/build
33
yarn-error.log
44
/coverage
5+
.rpt2_cache

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
name: "Produce coverage"
1414
- stage: Build
1515
node_js: "8"
16-
name: "Webpack build"
16+
name: "Rollup build"
1717
script: "yarn build"
1818
deploy:
1919
provider: npm

CHANGELOG.MD

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [2.0.3] - 2018-12-16
5+
- Migrated to rollup to improve package size and tree shaking
6+
47
## [2.0.2] - 2018-12-01
58
- Moved `@types/react-intl` to peerDependencies due to hoisting issues
69
- Made production package size smaller

config/jest/tsconfig.jest.json

Lines changed: 0 additions & 6 deletions
This file was deleted.

jest.config.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ module.exports = {
1010
'<rootDir>/src/**/*.{ts,tsx}',
1111
'!<rootDir>/src/test-utils/**',
1212
],
13-
globals: {
14-
'ts-jest': {
15-
tsConfig: '<rootDir>/config/jest/tsconfig.jest.json',
16-
},
17-
},
1813
transform: {
1914
'^.+\\.tsx?$': 'ts-jest',
2015
},

package.json

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
{
22
"name": "react-ocean-forms-react-intl",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "Library that adds react-intl support to react-ocean-forms.",
55
"main": "build/index.js",
6+
"module": "build/index.es.js",
67
"typings": "build/index.d.ts",
78
"private": false,
89
"sideEffects": false,
910
"scripts": {
1011
"test": "jest",
1112
"test:watch": "jest --watch",
1213
"test:coverage": "jest --coverage",
13-
"start": "webpack --watch --mode development",
14-
"build": "webpack -p",
14+
"start": "rollup -c -w",
15+
"build": "rollup -c",
1516
"lint": "tslint -t stylish --project ."
1617
},
1718
"dependencies": { },
@@ -23,40 +24,38 @@
2324
"react-ocean-forms": "^2.0.0"
2425
},
2526
"devDependencies": {
26-
"@babel/core": "^7.2.0",
27-
"@babel/plugin-proposal-object-rest-spread": "^7.2.0",
28-
"@babel/plugin-transform-react-jsx": "^7.2.0",
29-
"@babel/preset-env": "^7.2.0",
3027
"@types/enzyme": "^3.1.15",
3128
"@types/enzyme-adapter-react-16": "^1.0.3",
3229
"@types/jest": "^23.3.10",
33-
"@types/react": "^16.7.13",
30+
"@types/react": "^16.7.17",
3431
"@types/react-intl": "^2.3.14",
35-
"babel-loader": "^8.0.4",
36-
"babel-preset-react-app": "^6.1.0",
37-
"case-sensitive-paths-webpack-plugin": "^2.1.2",
38-
"clean-webpack-plugin": "^1.0.0",
3932
"coveralls": "^3.0.2",
40-
"enzyme": "^3.7.0",
41-
"enzyme-adapter-react-16": "^1.7.0",
33+
"enzyme": "^3.8.0",
34+
"enzyme-adapter-react-16": "^1.7.1",
4235
"jest": "^23.6.0",
4336
"prop-types": "^15.6.2",
4437
"react": "^16.6.3",
4538
"react-dom": "^16.6.3",
4639
"react-intl": "^2.7.2",
47-
"react-ocean-forms": "^2.1.3",
40+
"react-ocean-forms": "^2.1.5",
41+
"rollup": "^0.68.0",
42+
"rollup-plugin-commonjs": "^9.2.0",
43+
"rollup-plugin-filesize": "^5.0.1",
44+
"rollup-plugin-node-resolve": "^4.0.0",
45+
"rollup-plugin-typescript2": "^0.18.1",
4846
"ts-jest": "^23.10.5",
4947
"ts-loader": "^5.3.1",
5048
"tslint": "^5.11.0",
5149
"tslint-consistent-codestyle": "^1.14.1",
5250
"tslint-eaa-contrib": "^0.1.5",
5351
"tslint-microsoft-contrib": "^6.0.0",
5452
"tslint-react": "^3.6.0",
55-
"typescript": "^3.2.1",
56-
"webpack": "^4.27.1",
57-
"webpack-cli": "^3.1.2",
58-
"webpack-dev-server": "^3.1.10"
53+
"typescript": "^3.2.2"
5954
},
55+
"resolutions": {
56+
"@types/react": "16.7.17",
57+
"@types/enzyme": "^3.1.15"
58+
},
6059
"files": [
6160
"build/"
6261
],

rollup.config.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import typescript from 'rollup-plugin-typescript2';
2+
import nodeResolve from 'rollup-plugin-node-resolve';
3+
import commonjs from 'rollup-plugin-commonjs';
4+
import filesize from 'rollup-plugin-filesize';
5+
6+
const path = require('path');
7+
const basePath = process.cwd();
8+
const packageJson = require(path.resolve(basePath, './package.json'));
9+
10+
const externalDependencies = [
11+
...Object.keys(packageJson.dependencies || {}),
12+
...Object.keys(packageJson.peerDependencies || {})
13+
];
14+
15+
const getBaseConfig = (showFilesize = false, noTsDeclaration = false) => {
16+
const tsconfigOverride = noTsDeclaration ? {
17+
compilerOptions: {
18+
declaration: false,
19+
declarationMap: false
20+
}
21+
} : undefined;
22+
23+
return {
24+
input: "src/index.ts",
25+
plugins: [
26+
nodeResolve({
27+
preferBuiltins: true,
28+
browser: true
29+
}),
30+
typescript({
31+
clean: false,
32+
tsconfig: 'tsconfig.build.json',
33+
tsconfigOverride,
34+
}),
35+
commonjs({
36+
namedExports: {
37+
'moment': [
38+
'locale',
39+
],
40+
},
41+
}),
42+
showFilesize ? filesize() : null,
43+
],
44+
external: (id) => {
45+
return externalDependencies.some(dep => id.indexOf(dep) === 0);
46+
},
47+
};
48+
};
49+
50+
export default (commands) => {
51+
const cjsConfig = {
52+
...getBaseConfig(true),
53+
output: {
54+
file: packageJson.main,
55+
format: "cjs",
56+
exports: "named",
57+
sourcemap: true,
58+
},
59+
};
60+
61+
const esConfig = {
62+
...getBaseConfig(false, true),
63+
output: {
64+
file: packageJson.module,
65+
format: "es",
66+
exports: "named",
67+
sourcemap: true,
68+
}
69+
};
70+
71+
if (commands.watch === true) {
72+
return esConfig;
73+
} else {
74+
return [
75+
cjsConfig,
76+
esConfig,
77+
];
78+
}
79+
};

tsconfig.build.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
/*
44
* This file is used for the build process.
55
*/
6-
7-
"compilerOptions": {
8-
// Don't generate the declaration files for now...
6+
"compilerOptions": {
97
"declaration": true,
10-
"allowJs": false,
11-
"checkJs": false,
8+
"declarationDir": "build"
129
},
1310
"exclude": [
1411
// Make sure that all the test files are excluded from the build

tsconfig.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,14 @@
77
// Output stuff
88
"outDir": "build",
99
"jsx": "react",
10-
"declaration": true,
11-
"sourceMap": true,
10+
"declaration": false,
11+
"sourceMap": false,
1212
// Which libraries should be included
1313
"lib": [
14-
"es2017.object",
15-
"es2016",
16-
"dom"
14+
"es5",
15+
"dom",
1716
],
18-
"target": "es2015", // we target es2015. babel will do the rest
17+
"target": "es5",
1918
"moduleResolution": "node",
2019
// Some style guidelines
2120
"noImplicitAny": true,
@@ -26,5 +25,7 @@
2625
// disable javascript for now. The js sources are transpiled with webpack anyway
2726
"allowJs": false,
2827
"checkJs": false,
28+
"esModuleInterop": true,
29+
"allowSyntheticDefaultImports": true,
2930
}
3031
}

0 commit comments

Comments
 (0)