Skip to content

Commit

Permalink
refactor: overhaul build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Dec 9, 2021
1 parent 5844700 commit 5037c1a
Show file tree
Hide file tree
Showing 10 changed files with 1,497 additions and 831 deletions.
69 changes: 7 additions & 62 deletions docs/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,64 +1,9 @@
import fs from 'fs'
import path from 'path'
import { UserConfig } from 'vite'
import { defineConfig } from 'vite'
import prefresh from '@prefresh/vite'
import windicss from 'vite-plugin-windicss'
import { createConfig } from '../scripts/utils'

const pkg = require('../package.json')

function getPrismLanguages() {
const files = fs.readdirSync('node_modules/prismjs/components')
return files
.filter((file) => file.endsWith('.min.js'))
.map((file) => {
const [, name] = /\-([^\.]+)/.exec(file)!
return name
})
}

const config: UserConfig = {
define: {
DOCUP_VERSION: JSON.stringify(pkg.version),
PRISM_VERSION: JSON.stringify(require('prismjs/package').version),
PRISM_LANGUAGES: JSON.stringify(getPrismLanguages()),
},
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
},
resolve: {
alias: {
renderer:
process.env.NODE_ENV === 'fre'
? path.resolve('src/renderer/fre.ts')
: path.resolve('src/renderer/preact.ts'),
},
},
plugins: [
prefresh(),
windicss({
scan: {
fileExtensions: ['tsx'],
dirs: [path.resolve('src')],
},
}),
],
build: {
target: ['es2020', 'safari14', 'chrome88'],
minify: !process.env.DEBUG,
polyfillDynamicImport: false,
rollupOptions: {
input: [
path.join(__dirname, 'main.ts'),
path.join(__dirname, 'index.html'),
],
preserveEntrySignatures: 'strict',
output: {
// Disable vendor chunk, make everything bundled in a single file
manualChunks: undefined,
},
},
},
}

export default config
export default defineConfig({
...createConfig('preact', false),
// @ts-expect-error
plugins: [prefresh()],
})
21 changes: 9 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
"type": "git"
},
"files": [
"dist",
"!dist/docup.d.css",
"!dist/docup.esm.css"
"dist"
],
"types": "dist/docup.d.ts",
"unpkg": "dist/docup.min.js",
Expand All @@ -22,7 +20,7 @@
},
"scripts": {
"test": "echo skip",
"build": "rm -rf dist && cross-env NODE_ENV=production rollup -c",
"build": "rm -rf dist && cross-env NODE_ENV=production node -r esbuild-register scripts/build.ts",
"dev": "vite docs",
"dev:fre": "cross-env vite docs NODE_ENV=fre",
"build:website": "vite build docs && cp docs/README.md docs/dist/",
Expand All @@ -39,25 +37,24 @@
},
"devDependencies": {
"@egoist/rollup-plugin-ts-resolve": "^0.1.0",
"@prefresh/vite": "^2.1.0",
"@prefresh/vite": "^2.2.4",
"@rollup/plugin-alias": "^3.1.2",
"@rollup/plugin-commonjs": "^17.1.0",
"@rollup/plugin-node-resolve": "^11.2.0",
"@types/debug": "^4.1.5",
"@types/marked": "^1.2.2",
"@types/prismjs": "^1.16.3",
"clean-css": "^5.1.0",
"cross-env": "7.0.3",
"debug": "^4.3.1",
"esbuild": "^0.10.0",
"esbuild": "^0.14.2",
"esbuild-register": "^3.2.0",
"fre": "^2.0.4",
"prettier": "^2.2.1",
"rollup": "^2.42.4",
"rollup-plugin-dts": "^3.0.1",
"rollup-plugin-esbuild": "^3.0.2",
"rollup": "^2.61.0",
"rollup-plugin-dts": "^4.0.1",
"tailwindcss": "^2.2.19",
"type-fest": "^0.21.2",
"typescript": "^4.2.3",
"vite": "^2.1.3",
"vite-plugin-windicss": "^0.9.11"
"vite": "^2.7.1"
}
}
Loading

0 comments on commit 5037c1a

Please sign in to comment.