Skip to content

Commit

Permalink
build: migrate build process to vite library mode
Browse files Browse the repository at this point in the history
  • Loading branch information
cyntler committed Jun 7, 2024
1 parent 105f3a8 commit c5d901f
Show file tree
Hide file tree
Showing 15 changed files with 654 additions and 66 deletions.
626 changes: 595 additions & 31 deletions package-lock.json

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
"files": [
"dist/**"
],
"types": "./dist/esm/index.d.ts",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
"types": "./dist/index.d.ts",
"main": "./dist/react-doc-viewer.cjs",
"module": "./dist/react-doc-viewer.js",
"exports": {
"require": "./dist/cjs/index.js",
"import": "./dist/esm/index.js"
".": {
"require": "./dist/react-doc-viewer.cjs",
"import": "./dist/react-doc-viewer.js",
"types": "./dist/index.d.ts"
}
},
"scripts": {
"start": "storybook dev -p 6006",
"build": "rm -rf dist && npm run build:esm && npm run build:cjs",
"build:esm": "tsc --project tsconfig.build.json",
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --moduleResolution node --verbatimModuleSyntax false --outDir ./dist/cjs",
"postbuild:cjs": "echo '{\n \"type\": \"commonjs\"\n}' > dist/cjs/package.json",
"build": "rm -rf dist && tsc && vite build",
"test": "vitest run",
"lint": "eslint ./src --ext .ts,.tsx",
"prettier:check": "prettier --check .",
Expand Down Expand Up @@ -85,6 +85,8 @@
"release-it": "^17.3.0",
"storybook": "^8.1.5",
"typescript": "^5.4.5",
"vite": "^5.2.12",
"vite-plugin-dts": "^3.9.1",
"vitest": "^1.6.0",
"vitest-fetch-mock": "^0.2.2",
"webpack": "^5.91.0"
Expand Down
4 changes: 3 additions & 1 deletion src/components/DocumentNav.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { FC, useContext } from "react";
"use client";

import { FC, useContext } from "react";
import styled from "styled-components";
import { DocViewerContext } from "../store/DocViewerProvider";
import { nextDocument, previousDocument } from "../store/actions";
Expand Down
4 changes: 3 additions & 1 deletion src/components/FileName.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { FC, useContext } from "react";
"use client";

import { FC, useContext } from "react";
import styled from "styled-components";
import { DocViewerContext } from "../store/DocViewerProvider";
import { IStyledProps } from "..";
Expand Down
4 changes: 3 additions & 1 deletion src/components/HeaderBar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { FC, useContext } from "react";
"use client";

import { FC, useContext } from "react";
import styled from "styled-components";
import { DocViewerContext } from "../store/DocViewerProvider";
import { nextDocument, previousDocument } from "../store/actions";
Expand Down
10 changes: 3 additions & 7 deletions src/components/LoadingTimout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import React, {
FC,
PropsWithChildren,
useContext,
useEffect,
useState,
} from "react";
"use client";

import { FC, PropsWithChildren, useContext, useEffect, useState } from "react";
import { DocViewerContext } from "../store/DocViewerProvider";

export const LoadingTimeout: FC<PropsWithChildren> = ({ children }) => {
Expand Down
4 changes: 3 additions & 1 deletion src/components/ProxyRenderer.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { FC, useCallback } from "react";
"use client";

import { FC, useCallback } from "react";
import styled, { keyframes } from "styled-components";
import { setRendererRect } from "../store/actions";
import { DocRenderer, IConfig, IDocument, IStyledProps } from "../models";
Expand Down
2 changes: 1 addition & 1 deletion src/components/icons/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
"use client";

export interface IIconProps {
color?: string;
Expand Down
2 changes: 2 additions & 0 deletions src/cssStyles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import "react-pdf/dist/esm/Page/AnnotationLayer.css";
import "react-pdf/dist/esm/Page/TextLayer.css";
1 change: 1 addition & 0 deletions src/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ export const locales = {
};

export type AvailableLanguages = keyof typeof locales;

export const defaultLanguage: AvailableLanguages = "en";
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"use client";

import "./cssStyles";
import DocViewer from "./DocViewer";

export default DocViewer;
export { DocViewerRenderers } from "./renderers";
export * from "./models";
export * from "./utils/fileLoaders";
export { AvailableLanguages } from "./i18n";
export { type AvailableLanguages } from "./i18n";
export * from "./renderers";
16 changes: 5 additions & 11 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
{
"compilerOptions": {
"outDir": "./dist/esm",
"target": "ES6",
"module": "es2020",
"lib": ["dom", "dom.iterable", "esnext"],
"declaration": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"jsx": "react-jsx",
"noEmit": false,
"skipLibCheck": false,
"skipLibCheck": true,
"noEmit": true,
"resolveJsonModule": true,
"types": ["vitest/globals"]
}
},
"exclude": ["node_modules", "use-cases"]
}
1 change: 1 addition & 0 deletions use-cases/nextjs/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import "../../../../dist/index.css";

const inter = Inter({ subsets: ["latin"] });

Expand Down
2 changes: 1 addition & 1 deletion use-cases/nextjs/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import DocViewer, { IDocument } from "@cyntler/react-doc-viewer";
import DocViewer, { IDocument } from "../../../../";

import gifFile from "../../../../src/exampleFiles/gif-image.gif";
import pngFile from "../../../../src/exampleFiles/png-image.png";
Expand Down
19 changes: 18 additions & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
import { defineConfig } from "vitest/config";
import dsv from "@rollup/plugin-dsv";
import dts from "vite-plugin-dts";

export default defineConfig({
plugins: [dsv()],
plugins: [
dts({
tsconfigPath: "./tsconfig.build.json",
}),
dsv(),
],
build: {
lib: {
entry: "./src/index.tsx",
formats: ["es", "cjs"],
},
cssCodeSplit: true,
sourcemap: false,
rollupOptions: {
external: ["react"],
},
},
test: {
globals: true,
environment: "happy-dom",
Expand Down

0 comments on commit c5d901f

Please sign in to comment.