Support cjs, esm and iife modules

This commit is contained in:
Michael Vines
2018-08-22 21:43:32 -07:00
parent 5a0206bcfe
commit bf83497bbc
4 changed files with 923 additions and 43 deletions

View File

@ -10,7 +10,7 @@ after_success: npm run coveralls
before_deploy: before_deploy:
- cp -r doc solanaWeb3Api-$TRAVIS_BRANCH - cp -r doc solanaWeb3Api-$TRAVIS_BRANCH
- tar zcf solanaWeb3Api.tgz solanaWeb3Api-$TRAVIS_BRANCH - tar zcf solanaWeb3Api.tgz solanaWeb3Api-$TRAVIS_BRANCH
- cp lib/index.js solanaWeb3.min.js - cp lib/index.iife.js solanaWeb3.min.js
deploy: deploy:
- provider: pages - provider: pages

File diff suppressed because it is too large Load Diff

View File

@ -19,11 +19,13 @@
"publishConfig": { "publishConfig": {
"access": "public" "access": "public"
}, },
"main": "lib/index.js", "main": "lib/index.umd.js",
"module": "lib/index.esm.js",
"browser": "lib/index.iife.js",
"scripts": { "scripts": {
"clean": "rimraf ./coverage ./lib", "clean": "rimraf ./coverage ./lib",
"dev": "cross-env NODE_ENV=development rollup -c -o lib/index.js", "dev": "cross-env NODE_ENV=development rollup -c",
"build": "cross-env NODE_ENV=production rollup -c -o lib/index.js", "build": "cross-env NODE_ENV=production rollup -c",
"doc": "esdoc", "doc": "esdoc",
"doc:watch": "watch 'npm run doc' . --wait=1 --ignoreDirectoryPattern=/doc/", "doc:watch": "watch 'npm run doc' . --wait=1 --ignoreDirectoryPattern=/doc/",
"test": "cross-env NODE_ENV=test jest", "test": "cross-env NODE_ENV=test jest",
@ -32,14 +34,10 @@
"coveralls": "npm run test:cover && cat ./coverage/lcov.info | coveralls", "coveralls": "npm run test:cover && cat ./coverage/lcov.info | coveralls",
"flow": "flow", "flow": "flow",
"flow-typed": "npm run clean && flow-typed install --overwrite || true", "flow-typed": "npm run clean && flow-typed install --overwrite || true",
"lint": "eslint src", "lint": "eslint src examples",
"prepublish": "npm run clean && npm run test && npm run flow && npm run lint && npm run doc && npm run build" "prepublish": "npm run clean && npm run test && npm run flow && npm run lint && npm run doc && npm run build"
}, },
"dependencies": { "dependencies": {},
"babel-runtime": "^6.26.0",
"bs58": "^4.0.1",
"tweetnacl": "^1.0.0"
},
"devDependencies": { "devDependencies": {
"babel-core": "6.26.0", "babel-core": "6.26.0",
"babel-eslint": "8.2.3", "babel-eslint": "8.2.3",
@ -48,6 +46,8 @@
"babel-preset-env": "1.6.1", "babel-preset-env": "1.6.1",
"babel-preset-flow": "6.23.0", "babel-preset-flow": "6.23.0",
"babel-preset-stage-0": "6.24.1", "babel-preset-stage-0": "6.24.1",
"babel-runtime": "^6.26.0",
"bs58": "^4.0.1",
"coveralls": "3.0.0", "coveralls": "3.0.0",
"cross-env": "5.1.4", "cross-env": "5.1.4",
"enzyme": "3.3.0", "enzyme": "3.3.0",
@ -68,9 +68,13 @@
"rollup": "0.58.1", "rollup": "0.58.1",
"rollup-plugin-babel": "3.0.3", "rollup-plugin-babel": "3.0.3",
"rollup-plugin-commonjs": "9.1.0", "rollup-plugin-commonjs": "9.1.0",
"rollup-plugin-json": "^3.0.0",
"rollup-plugin-node-builtins": "^2.1.2",
"rollup-plugin-node-globals": "^1.2.1",
"rollup-plugin-node-resolve": "3.3.0", "rollup-plugin-node-resolve": "3.3.0",
"rollup-plugin-replace": "2.0.0", "rollup-plugin-replace": "2.0.0",
"rollup-plugin-uglify": "3.0.0", "rollup-plugin-uglify": "3.0.0",
"tweetnacl": "^1.0.0",
"watch": "^1.0.2" "watch": "^1.0.2"
} }
} }

View File

@ -1,42 +1,76 @@
import babel from 'rollup-plugin-babel'; import babel from 'rollup-plugin-babel';
import builtins from 'rollup-plugin-node-builtins';
import commonjs from 'rollup-plugin-commonjs'; import commonjs from 'rollup-plugin-commonjs';
import globals from 'rollup-plugin-node-globals';
import json from 'rollup-plugin-json';
import nodeResolve from 'rollup-plugin-node-resolve'; import nodeResolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace'; import replace from 'rollup-plugin-replace';
import uglify from 'rollup-plugin-uglify'; import uglify from 'rollup-plugin-uglify';
const env = process.env.NODE_ENV; const env = process.env.NODE_ENV;
const config = { function generateConfig(configType) {
input: 'src/index.js', const config = {
output: { input: 'src/index.js',
format: 'umd', plugins: [
name: 'solanaWeb3', nodeResolve(),
}, babel({
exclude: '**/node_modules/**',
runtimeHelpers: true,
}),
replace({
'process.env.NODE_ENV': JSON.stringify(env),
}),
commonjs(),
],
};
plugins: [ if (env === 'production') {
nodeResolve(), config.plugins.push(
babel({ uglify({
exclude: '**/node_modules/**', compress: {
runtimeHelpers: true, pure_getters: true,
}), unsafe: true,
replace({ unsafe_comps: true,
'process.env.NODE_ENV': JSON.stringify(env), warnings: false,
}), },
commonjs(), }),
], );
}; }
if (env === 'production') { switch (configType) {
config.plugins.push( case 'browser':
uglify({ config.output = [
compress: { {
pure_getters: true, file: 'lib/index.iife.js',
unsafe: true, format: 'iife',
unsafe_comps: true, name: 'solanaWeb3',
warnings: false,
}, },
}), ];
); config.plugins.unshift(json());
config.plugins.push(builtins());
config.plugins.push(globals());
break;
case 'node':
config.output = [
{
file: 'lib/index.cjs.js',
format: 'cjs',
},
{
file: 'lib/index.esm.js',
format: 'es',
},
];
break;
default:
throw new Error(`Unknown configType: ${configType}`);
}
return config;
} }
export default config; export default [
generateConfig('node'),
generateConfig('browser'),
];