diff --git a/example/config/webpack.config.js b/example/config/webpack.config.js index 87cc3939cc..48fcf2e56b 100644 --- a/example/config/webpack.config.js +++ b/example/config/webpack.config.js @@ -7,6 +7,7 @@ const { const webpack = require('webpack'); const HtmlReplaceWebpackPlugin = require('html-replace-webpack-plugin'); const GitRevisionPlugin = require('git-revision-webpack-plugin'); +const CopyPlugin = require('copy-webpack-plugin'); const gitRevisionPlugin = new GitRevisionPlugin(); const applicationVersion = gitRevisionPlugin.version().split('-')[0]; @@ -35,6 +36,16 @@ module.exports = override( }, ]), ), + addWebpackPlugin( + new CopyPlugin({ + patterns: [ + { + from: '../node_modules/ketcher-standalone/**/*.wasm', + to: '[name][ext]', + }, + ], + }), + ), ); module.exports.envVariables = envVariables; diff --git a/example/package.json b/example/package.json index 30a2878756..a361611311 100644 --- a/example/package.json +++ b/example/package.json @@ -56,6 +56,7 @@ "@types/react-dom": "^18.0.8", "@vitejs/plugin-react": "^4.0.0", "@welldone-software/why-did-you-render": "^4.3.1", + "copy-webpack-plugin": "^12.0.2", "cross-env": "^7.0.3", "customize-cra": "^1.0.0", "eslint": "^8.44.0", diff --git a/package-lock.json b/package-lock.json index eec4fd7603..361e996735 100644 --- a/package-lock.json +++ b/package-lock.json @@ -573,6 +573,7 @@ "@types/react-dom": "^18.0.8", "@vitejs/plugin-react": "^4.0.0", "@welldone-software/why-did-you-render": "^4.3.1", + "copy-webpack-plugin": "^12.0.2", "cross-env": "^7.0.3", "customize-cra": "^1.0.0", "eslint": "^8.44.0", @@ -5467,6 +5468,21 @@ } } }, + "node_modules/@rollup/plugin-alias": { + "version": "3.1.9", + "resolved": "https://registry.npmjs.org/@rollup/plugin-alias/-/plugin-alias-3.1.9.tgz", + "integrity": "sha512-QI5fsEvm9bDzt32k39wpOwZhVzRcL5ydcffUHMyLVaVaLeC70I8TJZ17F1z1eMoLu4E/UOcH9BWVkKpIKdrfiw==", + "dev": true, + "dependencies": { + "slash": "^3.0.0" + }, + "engines": { + "node": ">=8.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0" + } + }, "node_modules/@rollup/plugin-babel": { "version": "5.3.1", "resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.3.1.tgz", @@ -5654,6 +5670,18 @@ "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.24.51.tgz", "integrity": "sha512-1P1OROm/rdubP5aFDSZQILU0vrLCJ4fvHt6EoqHEM+2D/G5MK3bIaymUKLit8Js9gbns5UyJnkP/TZROLw4tUA==" }, + "node_modules/@sindresorhus/merge-streams": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/@sindresorhus/merge-streams/-/merge-streams-2.3.0.tgz", + "integrity": "sha512-LtoMMhxAlorcGhmFYI+LhPgbPZCkgP6ra1YL604EeF6U98pLlQ3iWIGMdWSC+vWmPBWBNgmDBAhnAobLROJmwg==", + "dev": true, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/@sinonjs/commons": { "version": "1.8.6", "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-1.8.6.tgz", @@ -10182,6 +10210,93 @@ "node": ">=0.10.0" } }, + "node_modules/copy-webpack-plugin": { + "version": "12.0.2", + "resolved": "https://registry.npmjs.org/copy-webpack-plugin/-/copy-webpack-plugin-12.0.2.tgz", + "integrity": "sha512-SNwdBeHyII+rWvee/bTnAYyO8vfVdcSTud4EIb6jcZ8inLeWucJE0DnxXQBjlQ5zlteuuvooGQy3LIyGxhvlOA==", + "dev": true, + "dependencies": { + "fast-glob": "^3.3.2", + "glob-parent": "^6.0.1", + "globby": "^14.0.0", + "normalize-path": "^3.0.0", + "schema-utils": "^4.2.0", + "serialize-javascript": "^6.0.2" + }, + "engines": { + "node": ">= 18.12.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + }, + "peerDependencies": { + "webpack": "^5.1.0" + } + }, + "node_modules/copy-webpack-plugin/node_modules/globby": { + "version": "14.0.1", + "resolved": "https://registry.npmjs.org/globby/-/globby-14.0.1.tgz", + "integrity": "sha512-jOMLD2Z7MAhyG8aJpNOpmziMOP4rPLcc95oQPKXBazW82z+CEgPFBQvEpRUa1KeIMUJo4Wsm+q6uzO/Q/4BksQ==", + "dev": true, + "dependencies": { + "@sindresorhus/merge-streams": "^2.1.0", + "fast-glob": "^3.3.2", + "ignore": "^5.2.4", + "path-type": "^5.0.0", + "slash": "^5.1.0", + "unicorn-magic": "^0.1.0" + }, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/copy-webpack-plugin/node_modules/path-type": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/path-type/-/path-type-5.0.0.tgz", + "integrity": "sha512-5HviZNaZcfqP95rwpv+1HDgUamezbqdSYTyzjTvwtJSnIH+3vnbmWsItli8OFEndS984VT55M3jduxZbX351gg==", + "dev": true, + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/copy-webpack-plugin/node_modules/schema-utils": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-4.2.0.tgz", + "integrity": "sha512-L0jRsrPpjdckP3oPug3/VxNKt2trR8TcabrM6FOAAlvC/9Phcmm+cuAgTlxBqdBR1WJx7Naj9WHw+aOmheSVbw==", + "dev": true, + "dependencies": { + "@types/json-schema": "^7.0.9", + "ajv": "^8.9.0", + "ajv-formats": "^2.1.1", + "ajv-keywords": "^5.1.0" + }, + "engines": { + "node": ">= 12.13.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/webpack" + } + }, + "node_modules/copy-webpack-plugin/node_modules/slash": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/slash/-/slash-5.1.0.tgz", + "integrity": "sha512-ZA6oR3T/pEyuqwMgAKT0/hAv8oAXckzbkmR0UkUosQ+Mc4RxGoJkRmwHgHufaenlyAgE1Mxgpdcrf75y6XcnDg==", + "dev": true, + "engines": { + "node": ">=14.16" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/core-js": { "version": "3.36.0", "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.36.0.tgz", @@ -15206,9 +15321,9 @@ } }, "node_modules/indigo-ketcher": { - "version": "1.21.0-rc.1", - "resolved": "https://registry.npmjs.org/indigo-ketcher/-/indigo-ketcher-1.21.0-rc.1.tgz", - "integrity": "sha512-W1T5E5fnv62jl7Ib+QyDcUAEJ4fKbeuKvpaCSnYiJwodtQcbmhhvTCh1qO6FxL/pScoJu4GqpIGUl+Y2/rLSUA==" + "version": "1.22.0-dev.2", + "resolved": "https://registry.npmjs.org/indigo-ketcher/-/indigo-ketcher-1.22.0-dev.2.tgz", + "integrity": "sha512-ihmZZBHpXrz8r7gfJoV3p/0gvD9ExGThfnsHhOfTuhjNmQm2jcTTwg8wqQYWAKbVYAPBUIGyaE1xy+50Ce3y9g==" }, "node_modules/inflight": { "version": "1.0.6", @@ -15420,7 +15535,6 @@ "resolved": "https://registry.npmjs.org/is-builtin-module/-/is-builtin-module-3.2.1.tgz", "integrity": "sha512-BSLE3HnV2syZ0FK0iMA/yUGplUeMmNz4AW5fnTunbCIqZi4vG3WjJT9FHMy5D69xmAYBHXQhJdALdpwVxV501A==", "dev": true, - "peer": true, "dependencies": { "builtin-modules": "^3.3.0" }, @@ -29408,6 +29522,18 @@ "node": ">=4" } }, + "node_modules/unicorn-magic": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/unicorn-magic/-/unicorn-magic-0.1.0.tgz", + "integrity": "sha512-lRfVq8fE8gz6QMBuDM6a+LO3IAzTi05H6gCVaUpir2E1Rwpo4ZUog45KpNXKC/Mn3Yb9UDuHumeFTo9iV/D9FQ==", + "dev": true, + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/unified": { "version": "9.2.2", "resolved": "https://registry.npmjs.org/unified/-/unified-9.2.2.tgz", @@ -34754,7 +34880,7 @@ "license": "Apache-2.0", "dependencies": { "@babel/runtime": "^7.17.9", - "indigo-ketcher": "1.21.0-rc.1", + "indigo-ketcher": "1.22.0-dev.2", "ketcher-core": "*" }, "devDependencies": { @@ -34762,9 +34888,10 @@ "@babel/plugin-transform-runtime": "^7.17.0", "@babel/preset-env": "^7.16.11", "@babel/preset-typescript": "^7.16.7", + "@rollup/plugin-alias": "^3.1.9", "@rollup/plugin-babel": "^5.2.1", "@rollup/plugin-commonjs": "^16.0.0", - "@rollup/plugin-node-resolve": "^10.0.0", + "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-strip": "^2.0.0", "@types/jest": "^27.0.3", "@types/node": "^16.11.12", @@ -34787,6 +34914,65 @@ "engines": { "node": ">=14" } + }, + "packages/ketcher-standalone/node_modules/@rollup/plugin-node-resolve": { + "version": "15.2.3", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.2.3.tgz", + "integrity": "sha512-j/lym8nf5E21LwBT4Df1VD6hRO2L2iwUeUmP7litikRsVp1H6NWx20NEp0Y7su+7XGc476GnXXc4kFeZNGmaSQ==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "@types/resolve": "1.20.2", + "deepmerge": "^4.2.2", + "is-builtin-module": "^3.2.1", + "is-module": "^1.0.0", + "resolve": "^1.22.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.78.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "packages/ketcher-standalone/node_modules/@rollup/plugin-node-resolve/node_modules/@rollup/pluginutils": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", + "integrity": "sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==", + "dev": true, + "dependencies": { + "@types/estree": "^1.0.0", + "estree-walker": "^2.0.2", + "picomatch": "^2.3.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, + "packages/ketcher-standalone/node_modules/@types/estree": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", + "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", + "dev": true + }, + "packages/ketcher-standalone/node_modules/@types/resolve": { + "version": "1.20.2", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", + "integrity": "sha512-60BCwRFOZCQhDncwQdxxeOEEkbc5dIMccYLwbxsS4TUNeVECQ/pBJ0j09mrHOl/JJvpRPGwO9SvE4nR2Nb/a4Q==", + "dev": true } } } diff --git a/packages/ketcher-standalone/package.json b/packages/ketcher-standalone/package.json index 4be028916d..4b2c6725d4 100644 --- a/packages/ketcher-standalone/package.json +++ b/packages/ketcher-standalone/package.json @@ -29,7 +29,7 @@ "node": ">=14" }, "scripts": { - "build": "cross-env NODE_ENV=production rollup -c -m true", + "build": "cross-env NODE_ENV=production rollup -c -m true && cross-env NODE_ENV=production BINARY_WASM=true rollup -c -m true", "start": "cross-env NODE_ENV=development rollup -c -m true -w", "test": "run-s test:prettier test:eslint:quiet test:types test:unit", "test:eslint": "eslint . --ext .ts,.js", @@ -42,7 +42,7 @@ }, "dependencies": { "@babel/runtime": "^7.17.9", - "indigo-ketcher": "1.21.0-rc.1", + "indigo-ketcher": "1.22.0-dev.2", "ketcher-core": "*" }, "devDependencies": { @@ -50,9 +50,10 @@ "@babel/plugin-transform-runtime": "^7.17.0", "@babel/preset-env": "^7.16.11", "@babel/preset-typescript": "^7.16.7", + "@rollup/plugin-alias": "^3.1.9", "@rollup/plugin-babel": "^5.2.1", "@rollup/plugin-commonjs": "^16.0.0", - "@rollup/plugin-node-resolve": "^10.0.0", + "@rollup/plugin-node-resolve": "^15.2.3", "@rollup/plugin-strip": "^2.0.0", "@types/jest": "^27.0.3", "@types/node": "^16.11.12", @@ -74,5 +75,15 @@ }, "files": [ "dist" - ] + ], + "exports": { + ".": { + "import": "./dist/index.modern.js", + "require": "./dist/index.js" + }, + "./dist/binaryWasm": { + "import": "./dist/binaryWasm/index.modern.js", + "require": "./dist/binaryWasm/index.js" + } + } } diff --git a/packages/ketcher-standalone/rollup.config.js b/packages/ketcher-standalone/rollup.config.js index 46873afa4e..1efbdaf061 100644 --- a/packages/ketcher-standalone/rollup.config.js +++ b/packages/ketcher-standalone/rollup.config.js @@ -8,6 +8,8 @@ import resolve from '@rollup/plugin-node-resolve'; import strip from '@rollup/plugin-strip'; import typescript from 'rollup-plugin-typescript2'; import webWorkerLoader from 'rollup-plugin-web-worker-loader'; +import copy from 'rollup-plugin-copy'; +import alias from '@rollup/plugin-alias'; import { license } from '../../license.ts'; const mode = { @@ -19,28 +21,10 @@ const extensions = ['.js', '.ts']; const isProduction = process.env.NODE_ENV === mode.PRODUCTION; const includePattern = 'src/**/*'; -const config = { +const baseConfig = { input: pkg.source, - output: [ - { - file: pkg.main, - exports: 'named', - format: 'cjs', - banner: license, - }, - { - file: pkg.module, - exports: 'named', - format: 'es', - banner: license, - }, - ], external: ['ketcher-core', /@babel\/runtime/], plugins: [ - del({ - targets: 'dist/*', - runOnce: true, - }), nodePolyfills(), resolve({ extensions }), commonjs(), @@ -65,4 +49,64 @@ const config = { ], }; -export default config; +const configWithWasmBase64 = { + ...baseConfig, + output: [ + { + file: pkg.exports['.'].require, + exports: 'named', + format: 'cjs', + banner: license, + }, + { + file: pkg.exports['.'].import, + exports: 'named', + format: 'es', + banner: license, + }, + ], + plugins: [ + del({ + targets: 'dist/*', + runOnce: true, + }), + ...baseConfig.plugins, + ], +}; +const configWithWasmFetch = { + ...baseConfig, + output: [ + { + file: pkg.exports['./dist/binaryWasm'].require, + exports: 'named', + format: 'cjs', + banner: license, + }, + { + file: pkg.exports['./dist/binaryWasm'].import, + exports: 'named', + format: 'es', + banner: license, + }, + ], + plugins: [ + ...baseConfig.plugins, + alias({ + entries: [ + { find: 'indigo-ketcher', replacement: 'indigo-ketcher/binaryWasm' }, + ], + }), + copy({ + targets: [ + { + src: '../../node_modules/indigo-ketcher/*.wasm', + dest: 'dist/binaryWasm', + }, + ], + }), + ], +}; + +export default process.env.BINARY_WASM + ? configWithWasmFetch + : configWithWasmBase64;