Webpack / ESM

This commit is contained in:
Aleksandr Kraiz
2022-04-24 01:24:39 +04:00
parent 0804b592d8
commit f4297f2a0d
4 changed files with 3179 additions and 154 deletions

3263
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +1,19 @@
{
"name": "@orionprotocol/sdk",
"version": "0.2.5",
"version": "0.2.6",
"description": "Orion Protocol SDK",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"main": "./lib/umd/index.js",
"module": "./lib/esm/index.js",
"types": "./lib/esm/index.d.ts",
"scripts": {
"start": "npm run build-ts && node lib/index.js",
"start": "npm run build && node lib/esm/index.js",
"develop": "concurrently -i -k -p \"[{name}]\" -n \"Node,TypeScript\" -c \"yellow.bold,cyan.bold\" \"yarn watch-js\" \"yarn watch-ts\"",
"clean": "rimraf lib/*",
"build-ts": "npm run typechain:generate-types && tsc --skipLibCheck",
"watch-ts": "npm run typechain:generate-types && tsc -w --skipLibCheck",
"watch-js": "nodemon lib/index.js",
"watch-js": "nodemon lib/esm/index.js",
"prepare": "npm run build",
"prebuild": "npm run typechain:generate-types && tsc",
"build": "webpack",
"test": "exit 0",
"coverage": "jest --coverage",
"lint:eslint": "eslint ./src --ext .ts,.js,.tsx,.jsx",
@@ -44,25 +47,33 @@
"@types/ws": "^8.5.3",
"@typescript-eslint/eslint-plugin": "^5.16.0",
"@typescript-eslint/parser": "^5.16.0",
"babel-core": "^6.26.3",
"babel-loader": "^8.2.5",
"concurrently": "^7.0.0",
"eslint": "^8.12.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-plugin-import": "^2.25.4",
"husky": "^7.0.4",
"jest": "^27.5.1",
"ts-loader": "^9.2.8",
"typechain": "^8.0.0",
"typescript": "^4.5.3"
"typescript": "^4.6.3",
"webpack": "^5.72.0",
"webpack-cli": "^4.9.2"
},
"dependencies": {
"@ethersproject/abstract-signer": "^5.6.0",
"@ethersproject/providers": "^5.6.2",
"bignumber.js": "^9.0.2",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.0",
"csprng": "^0.1.2",
"ethers": "^5.6.2",
"isomorphic-ws": "^4.0.1",
"just-clone": "^5.0.1",
"node-fetch": "^2.6.7",
"socket.io-client": "2.4.0",
"stream-browserify": "^3.0.0",
"tiny-invariant": "^1.2.0",
"uuid": "^8.3.2",
"websocket-heartbeat-js": "^1.1.0",

View File

@@ -1,6 +1,9 @@
{
"files": [
"./src/index.ts"
],
"include": [
"src"
"./src/**/*.ts"
],
"exclude": [
"node_modules",
@@ -17,8 +20,10 @@
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
/* Language and Environment */
"target": "es2018", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"target": "ES2015", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"lib": [
"ES2015",
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
// "jsx": "preserve", /* Specify what JSX code is generated. */
// "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
@@ -29,7 +34,7 @@
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
/* Modules */
"module": "CommonJS", /* Specify what module code is generated. */
"module": "ES2015", /* Specify what module code is generated. */
// "rootDir": "./", /* Specify the root folder within your source files. */
"moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
@@ -48,9 +53,9 @@
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
"sourceMap": true, /* Create source map files for emitted JavaScript files. */
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
"outDir": "./lib", /* Specify an output folder for all emitted files. */
"outDir": "./lib/esm", /* Specify an output folder for all emitted files. */
// "removeComments": true, /* Disable emitting comments. */
// "noEmit": true, /* Disable emitting files from a compilation. */
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
@@ -66,7 +71,7 @@
// "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
// "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
// "declarationDir": "./lib/typings/", /* Specify the output directory for generated declaration files. */
/* Interop Constraints */
// "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */

26
webpack.config.js Normal file
View File

@@ -0,0 +1,26 @@
const path = require("path");
module.exports = (env, argv) => {
return {
entry: {
index: path.resolve(__dirname, "./lib/esm/index.js")
},
output: {
path: path.resolve(__dirname, "./lib/umd"), // builds to ./lib/umd/
filename: "[name].js", // index.js
library: "orionprotocol", // aka window.myLibrary
libraryTarget: "umd", // supports commonjs, amd and web browsers
globalObject: "this"
},
module: {
rules: [{ test: /\.t|js$/, use: "babel-loader" }]
},
resolve: {
fallback: {
"crypto": require.resolve("crypto-browserify"),
"buffer": require.resolve("buffer/"),
"stream": require.resolve("stream-browserify"),
}
}
};
};