Skip to content

Commit

Permalink
Seperate web-component bundle and include deps into it
Browse files Browse the repository at this point in the history
  • Loading branch information
toddkao committed Jul 4, 2024
1 parent c207fa1 commit 9ae9627
Show file tree
Hide file tree
Showing 7 changed files with 459 additions and 50 deletions.
8 changes: 3 additions & 5 deletions examples/nextjs/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import { NextPage } from 'next';
import '@skip-go/widget/style.css';
import React from 'react';
import dynamic from 'next/dynamic';
import {
SwapWidget,
SwapWidgetProvider,
initializeSwapWidget,
} from '@skip-go/widget';
import { SwapWidget, SwapWidgetProvider } from '@skip-go/widget';

import { initializeSwapWidget } from '@skip-go/widget/web-component';

const NoSsrBase = (props: any) => <>{props.children}</>;

Expand Down
13 changes: 10 additions & 3 deletions packages/widget/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@skip-go/widget",
"description": "Swap widget",
"version": "0.1.0",
"version": "0.1.1-alpha.0",
"repository": "https://github.com/skip-mev/widget",
"type": "module",
"exports": {
Expand All @@ -12,6 +12,10 @@
"./style.css": {
"import": "./build/style.css",
"default": "./build/style.css"
},
"./web-component": {
"types": "./build/web-component.d.ts",
"import": "./build/web-component.es.js"
}
},
"types": "./build/index.d.ts",
Expand All @@ -24,8 +28,8 @@
],
"scripts": {
"start": "rollup --config rollup.config.js -w",
"dev": "rollup --config rollup.config.js -w",
"build": "rollup --config rollup.config.js",
"dev": "NODE_OPTIONS=--max-old-space-size=14000 rollup --config rollup.config.js -w",
"build": "NODE_OPTIONS=--max-old-space-size=14000 rollup --config rollup.config.js",
"lint": "eslint src --ext .ts",
"chains:generate": "tsx ./src/scripts/codegen.ts",
"postpublish": "yarn run post",
Expand Down Expand Up @@ -87,6 +91,9 @@
"@radix-ui/react-scroll-area": "^1.0.5",
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tooltip": "^1.0.7",
"@rollup/plugin-commonjs": "^26.0.1",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@skip-go/core": "workspace:packages/core",
"@solana/spl-token": "^0.4.6",
"@solana/wallet-adapter-react": "^0.15.35",
Expand Down
37 changes: 31 additions & 6 deletions packages/widget/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
import typescript from 'rollup-plugin-typescript2';
import postcss from 'rollup-plugin-postcss';
import json from '@rollup/plugin-json';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';

import packageJson from './package.json';

Expand All @@ -12,11 +15,6 @@ export default [
file: packageJson.exports['.'].import,
format: 'esm',
sourcemap: true,
globals: {
react: 'react',
'react-dom': 'react-dom',
'@r2wc/react-to-web-component': '@r2wc',
},
},
plugins: [
postcss({
Expand All @@ -32,9 +30,36 @@ export default [
useTsconfigDeclarationDir: true,
exclude: 'node_modules/**',
}),
resolve({
],
},
{
input: ['./src/web-component.ts'],
output: {
file: packageJson.exports['./web-component'].import,
format: 'esm',
sourcemap: true,
inlineDynamicImports: true,
},
plugins: [
postcss({
config: {
path: './postcss.config.js',
},
extensions: ['.css'],
minimize: true,
extract: 'style.css',
}),
peerDepsExternal(),
typescript({
useTsconfigDeclarationDir: true,
exclude: 'node_modules/**',
}),
nodeResolve({
browser: true,
preferBuiltins: false,
}),
json(),
commonjs(),
],
},
];
1 change: 0 additions & 1 deletion packages/widget/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import './styles/global.css';
export { SwapWidgetProvider } from './provider';
export { SwapWidget, SwapWidgetProps } from './ui';
export { initializeSwapWidget } from './ui/WebComponent';
export { useAssets } from './provider/assets';
export { useChains, useChainByID } from './hooks/use-chains';
1 change: 1 addition & 0 deletions packages/widget/src/web-component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { initializeSwapWidget } from './ui/WebComponent';
2 changes: 1 addition & 1 deletion packages/widget/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"declaration": true,
"declarationDir": "build",
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "Bundler",
"target": "ES2019",
"lib": ["es6", "dom", "es2016", "es2017", "es2021"],
"sourceMap": false,
Expand Down
Loading

0 comments on commit 9ae9627

Please sign in to comment.