Skip to content

Commit 9bee411

Browse files
author
Ian Tan
committed
chore(build): set up distribution build
1 parent da9c9ab commit 9bee411

File tree

6 files changed

+2941
-638
lines changed

6 files changed

+2941
-638
lines changed

.babelrc

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"presets": [
3+
[
4+
"@babel/env",
5+
{
6+
"modules": false,
7+
"targets": {
8+
"browsers": [
9+
">0.25%"
10+
]
11+
},
12+
"useBuiltIns": "usage"
13+
}
14+
],
15+
"@babel/typescript"
16+
],
17+
"env": {
18+
"development": {
19+
"plugins": [
20+
"@babel/transform-runtime"
21+
]
22+
},
23+
"production": {
24+
"plugins": [
25+
"@babel/transform-runtime",
26+
"transform-remove-console"
27+
]
28+
},
29+
"test": {
30+
"presets": [
31+
[
32+
"@babel/env",
33+
{
34+
"modules": "commonjs",
35+
"targets": {
36+
"node": "current"
37+
}
38+
}
39+
],
40+
[
41+
"@babel/stage-1",
42+
{
43+
"decoratorsLegacy": true
44+
}
45+
],
46+
"@babel/typescript"
47+
],
48+
"plugins": [
49+
"@babel/transform-runtime",
50+
"@babel/plugin-transform-modules-commonjs"
51+
]
52+
}
53+
},
54+
"plugins": [
55+
"@babel/plugin-syntax-dynamic-import",
56+
"@babel/plugin-syntax-import-meta",
57+
"@babel/plugin-proposal-class-properties",
58+
"@babel/plugin-proposal-json-strings",
59+
[
60+
"@babel/plugin-proposal-decorators",
61+
{
62+
"legacy": true
63+
}
64+
],
65+
"@babel/plugin-proposal-function-sent",
66+
"@babel/plugin-proposal-export-namespace-from",
67+
"@babel/plugin-proposal-numeric-separator",
68+
"@babel/plugin-proposal-throw-expressions",
69+
"@babel/plugin-proposal-export-default-from",
70+
"@babel/plugin-proposal-logical-assignment-operators",
71+
"@babel/plugin-proposal-optional-chaining",
72+
[
73+
"@babel/plugin-proposal-pipeline-operator",
74+
{
75+
"proposal": "minimal"
76+
}
77+
],
78+
"@babel/plugin-proposal-nullish-coalescing-operator",
79+
"@babel/plugin-proposal-do-expressions"
80+
]
81+
}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
node_modules
22
.DS_STORE
3+
.rpt2_cache
34
yarn-error.log
5+
dist

package.json

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
"name": "zilliqa.js",
33
"version": "0.0.1",
44
"description": "zilliqa js library",
5-
"main": "index.js",
5+
"main": "dist/zilliqa.js",
6+
"typings": "dist/index.d.ts",
67
"scripts": {
8+
"build": "rimraf dist/* && tsc --emitDeclarationOnly && cross-env NODE_ENV=production webpack --config webpack.config.js",
79
"test": "mocha"
810
},
911
"dependencies": {
@@ -16,14 +18,36 @@
1618
"valid-url": "^1.0.9"
1719
},
1820
"devDependencies": {
21+
"@babel/cli": "^7.0.0-beta.56",
22+
"@babel/core": "7.0.0-beta.54",
23+
"@babel/plugin-proposal-class-properties": "7.0.0-beta.54",
24+
"@babel/plugin-proposal-decorators": "7.0.0-beta.54",
25+
"@babel/plugin-proposal-do-expressions": "7.0.0-beta.54",
26+
"@babel/plugin-proposal-export-default-from": "7.0.0-beta.54",
27+
"@babel/plugin-proposal-export-namespace-from": "7.0.0-beta.54",
28+
"@babel/plugin-proposal-function-sent": "7.0.0-beta.54",
29+
"@babel/plugin-proposal-json-strings": "7.0.0-beta.54",
30+
"@babel/plugin-proposal-logical-assignment-operators": "7.0.0-beta.54",
31+
"@babel/plugin-proposal-nullish-coalescing-operator": "7.0.0-beta.54",
32+
"@babel/plugin-proposal-numeric-separator": "7.0.0-beta.54",
33+
"@babel/plugin-proposal-optional-chaining": "7.0.0-beta.54",
34+
"@babel/plugin-proposal-pipeline-operator": "7.0.0-beta.54",
35+
"@babel/plugin-proposal-throw-expressions": "7.0.0-beta.54",
36+
"@babel/plugin-syntax-dynamic-import": "7.0.0-beta.54",
37+
"@babel/plugin-syntax-import-meta": "7.0.0-beta.54",
38+
"@babel/plugin-transform-runtime": "^7.0.0-beta.56",
39+
"@babel/polyfill": "7.0.0-beta.54",
40+
"@babel/preset-env": "7.0.0-beta.54",
41+
"@babel/preset-typescript": "^7.0.0-beta.56",
42+
"@babel/runtime": "^7.0.0-beta.56",
1943
"@types/node": "^10.5.6",
20-
"babel-core": "^6.26.3",
21-
"babel-polyfill": "^6.26.0",
22-
"babel-preset-env": "^1.7.0",
23-
"babel-preset-es2015": "^6.24.1",
44+
"@types/valid-url": "^1.0.2",
45+
"babel-loader": "^8.0.0-beta.0",
46+
"babel-plugin-transform-remove-console": "^6.9.4",
2447
"babelify": "^8.0.0",
2548
"browserify": "^16.2.2",
2649
"chai": "*",
50+
"cross-env": "^5.2.0",
2751
"gulp": "^3.9.1",
2852
"gulp-uglify-es": "^1.0.4",
2953
"gulp-util": "^3.0.8",
@@ -32,6 +56,8 @@
3256
"tslint": "^5.11.0",
3357
"typescript": "^3.0.1",
3458
"vinyl-buffer": "^1.0.1",
35-
"vinyl-source-stream": "^1.1.2"
59+
"vinyl-source-stream": "^1.1.2",
60+
"webpack": "^4.16.5",
61+
"webpack-command": "^0.4.1"
3662
}
3763
}

tsconfig.json

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,23 @@
11
{
22
"compilerOptions": {
33
"allowSyntheticDefaultImports": true,
4-
"baseUrl": ".",
5-
"outDir": "build/dist",
6-
"module": "esnext",
4+
"outDir": "dist",
5+
"module": "commonjs",
76
"target": "es5",
8-
"lib": ["es6", "dom"],
7+
"lib": ["es2015", "es2016", "es2017", "dom"],
98
"sourceMap": true,
10-
"allowJs": true,
11-
"jsx": "react",
9+
"resolveJsonModule": true,
1210
"moduleResolution": "node",
11+
"declaration": true,
12+
"declarationDir": "dist",
1313
"rootDir": "src",
1414
"forceConsistentCasingInFileNames": false,
1515
"noImplicitReturns": true,
1616
"noImplicitThis": true,
1717
"noImplicitAny": false,
18-
"resolveJsonModule": true,
1918
"strictNullChecks": true,
2019
"suppressImplicitAnyIndexErrors": true,
21-
"noUnusedLocals": true,
22-
"typeRoots": [
23-
"node_modules/@types",
24-
"./typings",
25-
"./src/**/*.d.ts"
26-
]
20+
"noUnusedLocals": true
2721
},
28-
"exclude": [
29-
"node_modules",
30-
"build",
31-
"scripts",
32-
"webpack",
33-
"jest",
34-
"test"
35-
]
22+
"include": [ "src/**/*", "typings/**/*" ]
3623
}

webpack.config.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Base webpack configuration - to be used in ALL environments.
2+
/* eslint import/no-extraneous-dependencies: ["error", { devDependencies: true }] */
3+
const path = require('path');
4+
const webpack = require('webpack');
5+
6+
const baseConfig = {
7+
entry: {
8+
zilliqa: './src/index.ts',
9+
'zilliqa.min': './src/index.ts',
10+
},
11+
module: {
12+
rules: [
13+
{
14+
test: /\.ts$/,
15+
use: {
16+
loader: 'babel-loader',
17+
options: {
18+
babelrc: true,
19+
cacheDirectory: true,
20+
},
21+
},
22+
},
23+
],
24+
},
25+
output: {
26+
libraryTarget: 'umd',
27+
library: 'zilliqa.js',
28+
filename: '[name].js',
29+
path: path.join(__dirname, 'dist'),
30+
},
31+
resolve: {
32+
extensions: ['.ts', '.js'],
33+
},
34+
};
35+
36+
module.exports = baseConfig;

0 commit comments

Comments
 (0)