Skip to content

Commit

Permalink
fix: try new bundling strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
LexSwed committed May 16, 2023
1 parent 3a52cc0 commit 2c40396
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 127 deletions.
214 changes: 112 additions & 102 deletions package-lock.json

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions package.json
Expand Up @@ -5,18 +5,18 @@
"license": "Apache-2.0",
"type": "module",
"types": "dist/types/index.d.ts",
"main": "./dist/fxtrot-ui.cjs",
"module": "./dist/fxtrot-ui.mjs",
"main": "./dist/cjs/fxtrot-ui.cjs",
"module": "./dist/esm/fxtrot-ui.mjs",
"exports": {
".": {
"types": "./dist/types/index.d.ts",
"import": "./dist/fxtrot-ui.mjs",
"require": "./dist/fxtrot-ui.cjs"
"require": "./dist/cjs/lib.cjs",
"import": "./dist/esm/lib.mjs"
},
"./tailwind.preset": {
"types": "./dist/types/tailwind/preset.d.ts",
"import": "./dist/tailwind.preset.mjs",
"require": "./dist/tailwind.preset.cjs"
"require": "./dist/tailwind.preset.cjs",
"import": "./dist/tailwind.preset.mjs"
},
"./style.css": "./dist/style.css"
},
Expand All @@ -32,7 +32,7 @@
"build:preset": "vite build --config vite.tailwind-preset-config.mjs",
"dev": "npm run docs:dev",
"lint": "next lint --dir pages --dir src",
"typecheck": "tsc --noEmit --project ./tsconfig.without-next-modifications.json",
"typecheck": "tsc --noEmit",
"docs:dev": "next dev -p 3001",
"docs:build": "next build",
"docs:start": "next start",
Expand Down Expand Up @@ -66,13 +66,15 @@
"@radix-ui/react-visually-hidden": "^1.0.2",
"@tw-classed/core": "^1.4.4",
"clsx": "^1.2.1",
"react-keyed-flatten-children": "^1.3.0"
"react-keyed-flatten-children": "^1.3.0",
"tailwindcss": "^3.3.2"
},
"devDependencies": {
"@mdx-js/loader": "^2.3.0",
"@mdx-js/mdx": "^2.3.0",
"@mdx-js/react": "^2.3.0",
"@next/mdx": "^13.4.2",
"@rollup/plugin-node-resolve": "^15.0.2",
"@stitches/react": "^1.2.8",
"@types/glob": "^8.1.0",
"@types/jest": "^29.5.1",
Expand Down Expand Up @@ -114,7 +116,6 @@
"remark-gfm": "^3.0.1",
"remark-mdx-code-meta": "^2.0.0",
"remark-mdx-frontmatter": "^3.0.0",
"tailwindcss": "^3.3.2",
"typescript": "^5.0.4",
"typescript-plugin-css-modules": "^5.0.1",
"vite": "^4.3.6"
Expand Down
4 changes: 3 additions & 1 deletion src/pages-helpers/MdxProvider.tsx
Expand Up @@ -89,6 +89,8 @@ export const components = {
),
};

export const MdxProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => {
const MdxProvider: React.FC<{ children?: React.ReactNode }> = ({ children }) => {
return <MDXProvider components={components as any}>{children}</MDXProvider>;
};

export default MdxProvider;
4 changes: 2 additions & 2 deletions src/pages-helpers/MultilineCode.tsx
Expand Up @@ -29,14 +29,14 @@ export const MultilineCode = ({ code, language, fileName, lineNumber = true }: P
{tokens.map((line, i) => {
const lineProps = getLineProps({ line, key: i });
return (
<line {...lineProps} className={clsx('table-row text-sm', lineProps.className)}>
<div {...lineProps} className={clsx('table-row text-sm', lineProps.className)}>
{lineNumber && <span className="table-cell select-none text-end opacity-50 pr-4">{i + 1}</span>}
<span className="table-cell">
{line.map((token, key) => (
<span key={key} {...getTokenProps({ token, key })} />
))}
</span>
</line>
</div>
);
})}
</pre>
Expand Down
11 changes: 10 additions & 1 deletion src/pages/_app.tsx
Expand Up @@ -2,11 +2,20 @@ import './globals.css';
import localFont from 'next/font/local';

import { NextSeo } from 'next-seo';
import { lazy } from 'react';
import { ThemeProvider } from '@fxtrot/ui';

import { MdxProvider } from 'src/pages-helpers/MdxProvider';
import type { AppProps } from 'next/dist/shared/lib/router/router';

const MdxProvider = lazy(
() =>
import(
/* webpackPrefetch: true */
/* webpackChunkName: "my-chunk-name" */
'src/pages-helpers/MdxProvider'
)
);

const Inter = localFont({
src: '../../public/fonts/Inter-VariableFont_slnt,wght.ttf',
fallback: ['-apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, sans-serif'],
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -18,6 +18,7 @@
"moduleResolution": "node",
"resolveJsonModule": true,
"importHelpers": true,
"verbatimModuleSyntax": true,
"baseUrl": ".",
"paths": {
"@fxtrot/ui": ["src/lib"]
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.lib.json
Expand Up @@ -4,7 +4,8 @@
"noEmit": false,
"declaration": true,
"outDir": "dist/types",
"emitDeclarationOnly": true
"emitDeclarationOnly": true,
"verbatimModuleSyntax": true
},
"include": ["src/lib", "src/types"],
"exclude": ["node_modules"]
Expand Down
6 changes: 0 additions & 6 deletions tsconfig.without-next-modifications.json

This file was deleted.

27 changes: 22 additions & 5 deletions vite.config.mjs
Expand Up @@ -4,9 +4,18 @@ import react from '@vitejs/plugin-react';

import pkg from './package.json';

const makeExternalPredicate = (externalArr) => {
if (externalArr.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArr.join('|')})($|/)`);
return (id) => pattern.test(id);
};

/** @type {import('vite').UserConfig} */
export default defineConfig({
publicDir: false,
emptyOutDir: true,
plugins: [react()],
esbuild: {
target: ['chrome105', 'safari16'],
Expand All @@ -18,20 +27,28 @@ export default defineConfig({
entry: { lib: path.resolve(__dirname, './src/lib/index.ts') },
name: pkg.name,
formats: ['cjs', 'es'],
fileName: (format) => {
fileName: (format, entryName) => {
switch (format) {
case 'cjs':
return `fxtrot-ui.${format}`;
return `cjs/${entryName}.cjs`;
case 'es':
return `fxtrot-ui.mjs`;
return `esm/${entryName}.mjs`;
default:
return `fxtrot-ui.${format}.js`;
return `${entryName}/${format}`;
}
},
},
rollupOptions: {
external: [...Object.keys(pkg.dependencies), ...Object.keys(pkg.peerDependencies)],
// external: [/node_modules/],
external: makeExternalPredicate([
// Handles both dependencies and peer dependencies so we don't have to manually maintain a list
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
]),
output: {
chunkFileNames: '[name].[format]',
exports: 'named',
preserveModulesRoot: 'src/lib',
preserveModules: true,
globals: {
'react': 'React',
Expand Down

1 comment on commit 2c40396

@vercel
Copy link

@vercel vercel bot commented on 2c40396 May 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

fxtrot-ui – ./

fxtrot-ui-lexswed.vercel.app
fxtrot-ui.vercel.app
fxtrot-ui-git-main-lexswed.vercel.app

Please sign in to comment.