Skip to content

Commit

Permalink
feat: 🎸 plugins support cjs
Browse files Browse the repository at this point in the history
  • Loading branch information
haozi committed Jun 12, 2024
1 parent c87cf12 commit 07f33b4
Show file tree
Hide file tree
Showing 7 changed files with 1,018 additions and 849 deletions.
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"private": true,
"dependencies": {
"idmp": "2.0.0"
"idmp": "2.0.1"
},
"_dependencies": {
"idmp": "1.13.0-alpha.5"
Expand Down
22 changes: 16 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "idmp",
"version": "2.0.0",
"version": "2.0.1",
"keywords": [
"deduplicate network requests",
"idempotent function",
Expand Down Expand Up @@ -31,8 +31,18 @@
"default": "./dist/index.js"
}
},
"./node-fs": "./plugins/node-fs/dist/index.js",
"./browser-storage": "./plugins/browser-storage/dist/index.js"
"./node-fs": {
"default": {
"require": "./plugins/node-fs/dist/index.node.cjs",
"default": "./plugins/node-fs/dist/index.js"
}
},
"./browser-storage": {
"default": {
"require": "./plugins/browser-storage/dist/index.node.cjs",
"default": "./plugins/browser-storage/dist/index.js"
}
}
},
"main": "./dist/index.node.cjs",
"module": "./dist/index.js",
Expand All @@ -55,19 +65,19 @@
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
"@types/node": "^20.14.1",
"@types/node": "^20.14.2",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"@vitejs/plugin-legacy": "^5.4.1",
"@vitejs/plugin-react-swc": "^3.7.0",
"@vitest/coverage-istanbul": "^1.6.0",
"fs-extra": "^11.2.0",
"prettier": "^3.3.0",
"prettier": "^3.3.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-router-dom": "^6.23.1",
"typescript": "^5.4.5",
"vite": "^5.2.12",
"vite": "^5.2.13",
"vite-node": "^1.6.0",
"vite-plugin-banner": "^0.7.1",
"vite-plugin-dts": "^3.9.1",
Expand Down
1 change: 0 additions & 1 deletion plugins/browser-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "idmp-browser-storage",
"version": "1.0.0",
"private": true,
"type": "module",
"exports": {
".": "./dist/index.js"
},
Expand Down
63 changes: 56 additions & 7 deletions plugins/browser-storage/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,14 @@ const buildFile = async (buildOptions: DeepPartial<InlineConfig>) => {
mergeConfig(
{
plugins: [
// react(),
react(),
dts(),
banner(`/*! idmp v${version} | (c) github/haozi | MIT */`),
],
build: {
sourcemap: false,
// target: "chrome51",

target: 'node18',
externals: ['idmp'],
rollupOptions: {
external: [/^node:.*/, 'os', 'fs', 'idmp', 'fs-extra'],
},
target: 'es6',
lib: {
formats: ['es'],
entry: 'src/index.ts',
Expand All @@ -42,6 +37,7 @@ const buildFile = async (buildOptions: DeepPartial<InlineConfig>) => {
}
;(async () => {
await Promise.all([
// base
buildFile({
build: {
minify: false,
Expand All @@ -52,5 +48,58 @@ const buildFile = async (buildOptions: DeepPartial<InlineConfig>) => {
},
},
}),

// browser
buildFile({
build: {
minify: true,
lib: {
formats: ['umd'],
fileName: () => 'index.browser.umd.js',
},
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),

// browser esm
buildFile({
build: {
minify: true,
lib: {
formats: ['es'],
fileName: () => 'index.browser.esm.js',
},
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),

// node.cjs
buildFile({
build: {
minify: false,
lib: {
formats: ['cjs'],
fileName: () => 'index.node.cjs',
},
},
}),

// deno
buildFile({
build: {
minify: false,
lib: {
formats: ['es'],
fileName: () => 'index.deno.js',
},
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),
])
})()
1 change: 0 additions & 1 deletion plugins/node-fs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"name": "idmp-node-fs",
"version": "1.0.0",
"private": true,
"type": "module",
"exports": {
".": "./dist/index.js"
},
Expand Down
64 changes: 57 additions & 7 deletions plugins/node-fs/scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { build, mergeConfig, type InlineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
import dts from 'vite-plugin-dts'
import banner from 'vite-plugin-banner'
import { version, dependencies } from '../package.json'
import { version } from '../package.json'

type DeepPartial<T> = T extends object
? {
Expand All @@ -15,18 +15,14 @@ const buildFile = async (buildOptions: DeepPartial<InlineConfig>) => {
mergeConfig(
{
plugins: [
// react(),
react(),
dts(),
banner(`/*! idmp v${version} | (c) github/haozi | MIT */`),
],
build: {
sourcemap: false,
// target: "chrome51",

target: 'node18',
rollupOptions: {
external: [/^node:.*/, 'os', 'fs', ...Object.keys(dependencies)],
},
target: 'es6',
lib: {
formats: ['es'],
entry: 'src/index.ts',
Expand All @@ -41,6 +37,7 @@ const buildFile = async (buildOptions: DeepPartial<InlineConfig>) => {
}
;(async () => {
await Promise.all([
// base
buildFile({
build: {
minify: false,
Expand All @@ -51,5 +48,58 @@ const buildFile = async (buildOptions: DeepPartial<InlineConfig>) => {
},
},
}),

// browser
buildFile({
build: {
minify: true,
lib: {
formats: ['umd'],
fileName: () => 'index.browser.umd.js',
},
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),

// browser esm
buildFile({
build: {
minify: true,
lib: {
formats: ['es'],
fileName: () => 'index.browser.esm.js',
},
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),

// node.cjs
buildFile({
build: {
minify: false,
lib: {
formats: ['cjs'],
fileName: () => 'index.node.cjs',
},
},
}),

// deno
buildFile({
build: {
minify: false,
lib: {
formats: ['es'],
fileName: () => 'index.deno.js',
},
},
define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
}),
])
})()
Loading

0 comments on commit 07f33b4

Please sign in to comment.