Support cjs, esm and iife modules
This commit is contained in:
parent
5a0206bcfe
commit
bf83497bbc
|
@ -10,7 +10,7 @@ after_success: npm run coveralls
|
|||
before_deploy:
|
||||
- cp -r doc 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:
|
||||
- provider: pages
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -19,11 +19,13 @@
|
|||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"main": "lib/index.umd.js",
|
||||
"module": "lib/index.esm.js",
|
||||
"browser": "lib/index.iife.js",
|
||||
"scripts": {
|
||||
"clean": "rimraf ./coverage ./lib",
|
||||
"dev": "cross-env NODE_ENV=development rollup -c -o lib/index.js",
|
||||
"build": "cross-env NODE_ENV=production rollup -c -o lib/index.js",
|
||||
"dev": "cross-env NODE_ENV=development rollup -c",
|
||||
"build": "cross-env NODE_ENV=production rollup -c",
|
||||
"doc": "esdoc",
|
||||
"doc:watch": "watch 'npm run doc' . --wait=1 --ignoreDirectoryPattern=/doc/",
|
||||
"test": "cross-env NODE_ENV=test jest",
|
||||
|
@ -32,14 +34,10 @@
|
|||
"coveralls": "npm run test:cover && cat ./coverage/lcov.info | coveralls",
|
||||
"flow": "flow",
|
||||
"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"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-runtime": "^6.26.0",
|
||||
"bs58": "^4.0.1",
|
||||
"tweetnacl": "^1.0.0"
|
||||
},
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"babel-core": "6.26.0",
|
||||
"babel-eslint": "8.2.3",
|
||||
|
@ -48,6 +46,8 @@
|
|||
"babel-preset-env": "1.6.1",
|
||||
"babel-preset-flow": "6.23.0",
|
||||
"babel-preset-stage-0": "6.24.1",
|
||||
"babel-runtime": "^6.26.0",
|
||||
"bs58": "^4.0.1",
|
||||
"coveralls": "3.0.0",
|
||||
"cross-env": "5.1.4",
|
||||
"enzyme": "3.3.0",
|
||||
|
@ -68,9 +68,13 @@
|
|||
"rollup": "0.58.1",
|
||||
"rollup-plugin-babel": "3.0.3",
|
||||
"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-replace": "2.0.0",
|
||||
"rollup-plugin-uglify": "3.0.0",
|
||||
"tweetnacl": "^1.0.0",
|
||||
"watch": "^1.0.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,42 +1,76 @@
|
|||
import babel from 'rollup-plugin-babel';
|
||||
import builtins from 'rollup-plugin-node-builtins';
|
||||
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 replace from 'rollup-plugin-replace';
|
||||
import uglify from 'rollup-plugin-uglify';
|
||||
|
||||
const env = process.env.NODE_ENV;
|
||||
|
||||
const config = {
|
||||
input: 'src/index.js',
|
||||
output: {
|
||||
format: 'umd',
|
||||
name: 'solanaWeb3',
|
||||
},
|
||||
function generateConfig(configType) {
|
||||
const config = {
|
||||
input: 'src/index.js',
|
||||
plugins: [
|
||||
nodeResolve(),
|
||||
babel({
|
||||
exclude: '**/node_modules/**',
|
||||
runtimeHelpers: true,
|
||||
}),
|
||||
replace({
|
||||
'process.env.NODE_ENV': JSON.stringify(env),
|
||||
}),
|
||||
commonjs(),
|
||||
],
|
||||
};
|
||||
|
||||
plugins: [
|
||||
nodeResolve(),
|
||||
babel({
|
||||
exclude: '**/node_modules/**',
|
||||
runtimeHelpers: true,
|
||||
}),
|
||||
replace({
|
||||
'process.env.NODE_ENV': JSON.stringify(env),
|
||||
}),
|
||||
commonjs(),
|
||||
],
|
||||
};
|
||||
if (env === 'production') {
|
||||
config.plugins.push(
|
||||
uglify({
|
||||
compress: {
|
||||
pure_getters: true,
|
||||
unsafe: true,
|
||||
unsafe_comps: true,
|
||||
warnings: false,
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
if (env === 'production') {
|
||||
config.plugins.push(
|
||||
uglify({
|
||||
compress: {
|
||||
pure_getters: true,
|
||||
unsafe: true,
|
||||
unsafe_comps: true,
|
||||
warnings: false,
|
||||
switch (configType) {
|
||||
case 'browser':
|
||||
config.output = [
|
||||
{
|
||||
file: 'lib/index.iife.js',
|
||||
format: 'iife',
|
||||
name: 'solanaWeb3',
|
||||
},
|
||||
}),
|
||||
);
|
||||
];
|
||||
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'),
|
||||
];
|
||||
|
|
Loading…
Reference in New Issue