Skip to content

Commit

Permalink
feat: build for the esm, cjs, and umd formats
Browse files Browse the repository at this point in the history
  • Loading branch information
bent10 committed Oct 19, 2023
1 parent 7418f11 commit 30bc148
Show file tree
Hide file tree
Showing 14 changed files with 310 additions and 366 deletions.
271 changes: 147 additions & 124 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@types/react-dom": "^18.2.13",
"doogu": "^3.2.7",
"marked": "^9.1.2",
"marked-sequential-hooks": "^0.0.0-development",
"moo": "^0.5.2",
"prettier-plugin-svelte": "^3.0.3",
"pupa": "^3.1.0",
Expand Down
18 changes: 8 additions & 10 deletions packages/code-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@
"stilearning-marked-extensions"
],
"type": "module",
"main": "dist/index.umd.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"main": "./dist/index.cjs",
"browser": "./dist/index.umd.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.umd.cjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
},
Expand All @@ -36,12 +37,9 @@
"readme.md"
],
"scripts": {
"start": "npm run prod",
"prod": "vite build && vite",
"dev": "vite build:ssr --watch",
"build": "npm run build:ssr && npm run build:prod && npm run types",
"build:ssr": "vite build --ssr src/index.ts",
"build:prod": "vite build",
"start": "vite",
"dev": "vite build --watch",
"build": "vite build && npm run types",
"test": "vitest",
"coverage": "vitest run --coverage",
"types": "tsc -d --emitDeclarationOnly --outDir ./dist",
Expand Down
51 changes: 20 additions & 31 deletions packages/code-format/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,28 @@
/// <reference types="vitest" />
import { resolve } from 'node:path'
import { defineConfig, type BuildOptions } from 'vite'
import { defineConfig } from 'vite'
import cacheDir from 'vite-plugin-cachedir'

export default defineConfig(({ command, ssrBuild }) => {
const isBuildLib = command === 'build' && !ssrBuild
const build: BuildOptions = {}

if (isBuildLib) {
Object.assign(build, {
emptyOutDir: false,
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'markedCodeFormat',
formats: ['umd'],
fileName: 'index'
},
rollupOptions: {
external: ['marked', 'prettier'],
output: {
globals: {
marked: 'marked',
prettier: 'prettier'
}
export default defineConfig({
plugins: [cacheDir()],
build: {
lib: {
entry: 'src/index.ts',
name: 'markedCodeFormat',
formats: ['es', 'cjs', 'umd'],
fileName: 'index'
},
rollupOptions: {
external: ['marked', 'prettier'],
output: {
globals: {
marked: 'marked',
prettier: 'prettier'
}
}
})
}

return {
plugins: [cacheDir()],
build,
test: {
globals: true,
include: ['test/*.test.ts']
}
},
test: {
globals: true,
include: ['test/*.test.ts']
}
})
18 changes: 8 additions & 10 deletions packages/code-preview/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
"stilearning-marked-extensions"
],
"type": "module",
"main": "dist/index.umd.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"main": "./dist/index.cjs",
"browser": "./dist/index.umd.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.umd.cjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
},
Expand All @@ -38,12 +39,9 @@
"readme.md"
],
"scripts": {
"start": "npm run prod",
"prod": "vite build && vite",
"dev": "vite build:ssr --watch",
"build": "npm run build:ssr && npm run build:prod && npm run types",
"build:ssr": "vite build --ssr src/index.ts",
"build:prod": "vite build",
"start": "vite",
"dev": "vite build --watch",
"build": "vite build && npm run types",
"test": "vitest",
"coverage": "vitest run --coverage",
"types": "tsc -d --emitDeclarationOnly --outDir ./dist",
Expand Down
48 changes: 18 additions & 30 deletions packages/code-preview/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
/// <reference types="vitest" />
import { resolve } from 'node:path'
import { defineConfig, type BuildOptions } from 'vite'
import { defineConfig } from 'vite'
import cacheDir from 'vite-plugin-cachedir'

export default defineConfig(({ command, ssrBuild }) => {
const isBuildLib = command === 'build' && !ssrBuild
const build: BuildOptions = {}

if (isBuildLib) {
Object.assign(build, {
emptyOutDir: false,
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'markedCodePreview',
formats: ['umd'],
fileName: 'index'
},
rollupOptions: {
external: ['marked'],
output: { globals: { marked: 'marked' } }
}
})
}

return {
plugins: [cacheDir()],
ssr: {
noExternal: ['pupa', 'escape-goat', 'moo']
export default defineConfig({
plugins: [cacheDir()],
build: {
lib: {
entry: 'src/index.ts',
name: 'markedCodePreview',
formats: ['es', 'cjs', 'umd'],
fileName: 'index'
},
build,
test: {
globals: true,
include: ['test/*.test.ts']
rollupOptions: {
external: ['marked', 'attributes-parser'],
output: {
globals: { marked: 'marked', 'attributes-parser': 'parseAttrs' }
}
}
},
test: {
globals: true,
include: ['test/*.test.ts']
}
})
18 changes: 8 additions & 10 deletions packages/footnote/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
"stilearning-marked-extensions"
],
"type": "module",
"main": "dist/index.umd.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"main": "./dist/index.cjs",
"browser": "./dist/index.umd.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.umd.cjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
},
Expand All @@ -33,12 +34,9 @@
"readme.md"
],
"scripts": {
"start": "npm run prod",
"prod": "vite build && vite",
"dev": "vite build:ssr --watch",
"build": "npm run build:ssr && npm run build:prod && npm run types",
"build:ssr": "vite build --ssr src/index.ts",
"build:prod": "vite build",
"start": "vite",
"dev": "vite build --watch",
"build": "vite build && npm run types",
"test": "vitest",
"coverage": "vitest run --coverage",
"types": "tsc -d --emitDeclarationOnly --outDir ./dist",
Expand Down
43 changes: 16 additions & 27 deletions packages/footnote/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,22 @@
/// <reference types="vitest" />
import { resolve } from 'node:path'
import { defineConfig, type BuildOptions } from 'vite'
import { defineConfig } from 'vite'
import cacheDir from 'vite-plugin-cachedir'

export default defineConfig(({ command, ssrBuild }) => {
const isBuildLib = command === 'build' && !ssrBuild
const build: BuildOptions = {}

if (isBuildLib) {
Object.assign(build, {
emptyOutDir: false,
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'markedFootnote',
formats: ['umd'],
fileName: 'index'
},
rollupOptions: {
external: ['marked']
}
})
}

return {
plugins: [cacheDir()],
build,
test: {
globals: true,
include: ['test/*.test.ts']
export default defineConfig({
plugins: [cacheDir()],
build: {
lib: {
entry: 'src/index.ts',
name: 'markedFootnote',
formats: ['es', 'cjs', 'umd'],
fileName: 'index'
},
rollupOptions: {
external: ['marked']
}
},
test: {
globals: true,
include: ['test/*.test.ts']
}
})
22 changes: 11 additions & 11 deletions packages/hook-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@
"stilearning-marked-extensions"
],
"type": "module",
"main": "dist/index.umd.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"main": "./dist/index.cjs",
"browser": "./dist/index.umd.cjs",
"module": "./dist/index.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"require": "./dist/index.umd.cjs",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
}
},
Expand All @@ -39,12 +40,9 @@
"readme.md"
],
"scripts": {
"start": "npm run prod",
"prod": "vite build && vite",
"dev": "vite build:ssr --watch",
"build": "npm run build:ssr && npm run build:prod && npm run types",
"build:ssr": "vite build --ssr src/index.ts",
"build:prod": "vite build",
"start": "vite",
"dev": "vite build --watch",
"build": "vite build && npm run types",
"test": "vitest",
"coverage": "vitest run --coverage",
"types": "tsc -d --emitDeclarationOnly --outDir ./dist",
Expand All @@ -56,7 +54,9 @@
"loadee": "^2.2.0"
},
"peerDependencies": {
"marked": ">=7.0.0",
"marked": ">=7.0.0"
},
"optionalDependencies": {
"marked-sequential-hooks": ">=1.0.0"
}
}
55 changes: 22 additions & 33 deletions packages/hook-data/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,30 @@
/// <reference types="vitest" />
import { resolve } from 'node:path'
import { defineConfig, type BuildOptions } from 'vite'
import { defineConfig } from 'vite'
import cacheDir from 'vite-plugin-cachedir'

export default defineConfig(({ command, ssrBuild }) => {
const isBuildLib = command === 'build' && !ssrBuild
const build: BuildOptions = {}

if (isBuildLib) {
Object.assign(build, {
emptyOutDir: false,
lib: {
entry: resolve(__dirname, 'src/index.ts'),
name: 'markedHookData',
formats: ['umd'],
fileName: 'index'
},
rollupOptions: {
external: ['marked', 'fast-glob', 'loadee', 'node:path'],
output: {
globals: {
marked: 'marked',
'fast-glob': 'fg',
loadee: 'loadee',
'node:path': 'path'
}
export default defineConfig({
plugins: [cacheDir()],
build: {
lib: {
entry: 'src/index.ts',
name: 'markedHookData',
formats: ['es', 'cjs', 'umd'],
fileName: 'index'
},
rollupOptions: {
external: ['marked', 'fast-glob', 'loadee', 'node:path'],
output: {
globals: {
marked: 'marked',
loadee: 'loadee',
'fast-glob': 'fg',
'node:path': 'path'
}
}
})
}

return {
plugins: [cacheDir()],
build,
test: {
globals: true,
include: ['test/*.test.ts']
}
},
test: {
globals: true,
include: ['test/*.test.ts']
}
})
Loading

0 comments on commit 30bc148

Please sign in to comment.