Skip to content

Commit

Permalink
fix vercel envs with vite config
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanto committed Mar 15, 2022
1 parent 1b09348 commit bc189d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/next-deploy-notifications/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next-deploy-notifications",
"version": "0.1.1",
"version": "0.1.2",
"license": "MIT",
"exports": {
".": {
Expand Down
33 changes: 18 additions & 15 deletions packages/next-deploy-notifications/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import typescript from "@rollup/plugin-typescript";
import { readFileSync } from "fs";
import { resolve, join } from "path";
import { readdir, writeFile, readFile } from "fs/promises";
import { resolve } from "path";

const pkg = JSON.parse(
readFileSync(new URL("./package.json", import.meta.url), { encoding: "utf8" })
Expand All @@ -12,37 +11,41 @@ const pkg = JSON.parse(
let externalDependencies = ["dependencies", "peerDependencies"].reduce(
(result, group) => [
...result,
...(pkg[group] ? Object.keys(pkg[group]) : [])
...(pkg[group] ? Object.keys(pkg[group]) : []),
],
[]
);

export default defineConfig({
plugins: [react()],
define: {
"process.env.VERCEL": "process.env.VERCEL",
"process.env.VERCEL_GIT_COMMIT_SHA": "process.env.VERCEL_GIT_COMMIT_SHA",
},
build: {
lib: {
entry: resolve(__dirname, "src/react.tsx"),
name: "next-deploy-notifications"
name: "next-deploy-notifications",
},
rollupOptions: {
external: [...externalDependencies, /react\/.+/, /^node:/],
input: {
react: resolve(__dirname, "src/react.tsx"),
api: resolve(__dirname, "src/api.ts")
api: resolve(__dirname, "src/api.ts"),
},
plugins: [typescript(), singleTypeDef()],
output: [
{
entryFileNames: "[name].js",
format: "es"
format: "es",
},
{
entryFileNames: "[name].[format].js",
format: "cjs"
}
]
}
}
format: "cjs",
},
],
},
},
});

function singleTypeDef() {
Expand All @@ -51,14 +54,14 @@ function singleTypeDef() {

async generateBundle(options, bundle) {
let files = Object.keys(bundle);
let defFiles = files.filter(file => file.match(/^\w+\.d\.ts$/));
let types = defFiles.map(file => bundle[file].source);
let defFiles = files.filter((file) => file.match(/^\w+\.d\.ts$/));
let types = defFiles.map((file) => bundle[file].source);
let content = types.join("\n");
this.emitFile({
type: "asset",
fileName: "types.d.ts",
source: content
source: content,
});
}
},
};
}

0 comments on commit bc189d1

Please sign in to comment.