Skip to content

Commit

Permalink
include d.ts file in export
Browse files Browse the repository at this point in the history
  • Loading branch information
rommguy committed Mar 2, 2024
1 parent 681ef51 commit e967e5d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 27 deletions.
7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@
"main": "dist/index.umd.js",
"module": "dist/index.es.js",
"types": "dist/src/customScroll.d.ts",
"exports": {
".": {
"import": "./dist/index.es.js",
"require": "./dist/index.umd.js"
}
},
"files": [
"/dist"
],
Expand All @@ -21,6 +15,7 @@
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"build:example": "tsc && vite build --mode example",
"prepare": "npm run build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
Expand Down
85 changes: 64 additions & 21 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,71 @@ import react from "@vitejs/plugin-react-swc";
import path from "path";
import dts from "vite-plugin-dts";

// https://vitejs.dev/config/
export default defineConfig({
build: {
lib: {
entry: path.resolve(__dirname, "index.ts"),
name: "react-custom-scroll",
fileName: (format) => `index.${format}.js`,
},
rollupOptions: {
external: ["react", "react-dom"],
output: {
globals: {
react: "React",
"react-dom": "ReactDOM",
export default defineConfig(({ mode }) => {
const isProdBuild = mode !== "example";
const entry = isProdBuild
? path.resolve(__dirname, "index.ts")
: path.resolve(__dirname, "src/main.tsx");

const external = isProdBuild ? ["react", "react-dom"] : [];
const globals = isProdBuild
? { react: "React", "react-dom": "ReactDOM" }
: {};

const baseConfig = {
build: {
lib: {
entry,
name: "react-custom-scroll",
fileName: (format) => `index.${format}.js`,
},
rollupOptions: {
external,
output: {
globals,
},
},
sourcemap: true,
emptyOutDir: true,
},
sourcemap: true,
emptyOutDir: true,
},
plugins: [react(), dts()],
server: {
port: 5174,
},
plugins: [react(), dts({ insertTypesEntry: true })],
server: {
port: 5174,
},
};

if (isProdBuild) {
return baseConfig;
}

return {
...baseConfig,
build: { ...baseConfig.build, outDir: "exampleDist" },
};
});

// https://vitejs.dev/config/
// export default defineConfig({
// build: {
// lib: {
// entry: path.resolve(__dirname, "index.ts"),
// name: "react-custom-scroll",
// fileName: (format) => `index.${format}.js`,
// },
// rollupOptions: {
// external: ["react", "react-dom"],
// output: {
// globals: {
// react: "React",
// "react-dom": "ReactDOM",
// },
// },
// },
// sourcemap: true,
// emptyOutDir: true,
// },
// plugins: [react(), dts()],
// server: {
// port: 5174,
// },
// });

0 comments on commit e967e5d

Please sign in to comment.