build: handle shared files better (#72) (#114)

fix #72
pull/116/head
Kia King Ishii 4 years ago committed by GitHub
parent e682675f96
commit df97d96909
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

2
.gitignore vendored

@ -1,4 +1,6 @@
/dist /dist
/node_modules /node_modules
/src/client/shared
/src/node/shared
*.log *.log
.DS_Store .DS_Store

@ -27,13 +27,14 @@
}, },
"homepage": "https://github.com/vuejs/vitepress/tree/master/#readme", "homepage": "https://github.com/vuejs/vitepress/tree/master/#readme",
"scripts": { "scripts": {
"dev": "run-p dev-client dev-client-copy dev-node dev-shared", "dev": "yarn dev-shared && yarn dev-start",
"dev-start": "run-p dev-client dev-node dev-watch",
"dev-client": "tsc -w -p src/client", "dev-client": "tsc -w -p src/client",
"dev-client-copy": "node scripts/watchAndCopy",
"dev-node": "tsc -w -p src/node", "dev-node": "tsc -w -p src/node",
"dev-shared": "tsc -w -p src/shared", "dev-shared": "node scripts/copyShared",
"dev-watch": "node scripts/watchAndCopy",
"release": "bash scripts/release.sh", "release": "bash scripts/release.sh",
"build": "rimraf -rf dist && tsc -p src/client && tsc -p src/node && tsc -p src/shared && node scripts/copy", "build": "rimraf -rf dist && node scripts/copyShared && tsc -p src/client && tsc -p src/node && node scripts/copyClient",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s" "changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"
}, },
"engines": { "engines": {

@ -0,0 +1,7 @@
const fs = require('fs-extra')
const glob = require('globby')
glob.sync('src/shared/**/*.ts').forEach((file) => {
fs.copy(file, file.replace(/^src\//, 'src/node/'))
fs.copy(file, file.replace(/^src\//, 'src/client/'))
})

@ -2,12 +2,31 @@
const fs = require('fs-extra') const fs = require('fs-extra')
const chokidar = require('chokidar') const chokidar = require('chokidar')
function toDest(file) { function toClientAndNode(method, file) {
if (method === 'copy') {
fs.copy(file, file.replace(/^src\//, 'src/node/'))
fs.copy(file, file.replace(/^src\//, 'src/client/'))
} else if (method === 'remove') {
fs.remove(file.replace(/^src\//, 'src/node/'))
fs.remove(file.replace(/^src\//, 'src/client/'))
}
}
function toDist(file) {
return file.replace(/^src\//, 'dist/') return file.replace(/^src\//, 'dist/')
} }
// copy shared files to the client and node directory whenever they change.
chokidar
.watch('src/shared/**/*.ts')
.on('change', (file) => toClientAndNode('copy', file))
.on('add', (file) => toClientAndNode('copy', file))
.on('unlink', (file) => toClientAndNode('remove', file))
// copy non ts files, such as an html or css, to the dist directory whenever
// they change.
chokidar chokidar
.watch('src/client/**/!(*.ts|tsconfig.json)') .watch('src/client/**/!(*.ts|tsconfig.json)')
.on('change', (file) => fs.copy(file, toDest(file))) .on('change', (file) => fs.copy(file, toDist(file)))
.on('add', (file) => fs.copy(file, toDest(file))) .on('add', (file) => fs.copy(file, toDist(file)))
.on('unlink', (file) => fs.remove(toDest(file))) .on('unlink', (file) => fs.remove(toDist(file)))

@ -2,22 +2,20 @@
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"outDir": "../../dist", "outDir": "../../dist/client",
"module": "esnext", "module": "esnext",
"lib": ["ESNext", "DOM"], "lib": ["ESNext", "DOM"],
"types": ["vite"], "types": ["vite"],
"paths": { "paths": {
"/@app/*": ["app/*"], "/@app/*": ["app/*"],
"/@theme/*": ["theme-default/*"], "/@theme/*": ["theme-default/*"],
"/@shared/*": ["../shared/*"], "/@shared/*": ["shared/*"],
"/@types/*": ["../../types/*"],
"vitepress": ["app/exports.ts"] "vitepress": ["app/exports.ts"]
} }
}, },
"include": [ "include": [
".", ".",
"../../types/shared.d.ts", "../../types/shared.d.ts",
],
"exclude": [
"../shared"
] ]
} }

@ -5,7 +5,7 @@ import globby from 'globby'
import { createResolver, APP_PATH } from './resolver' import { createResolver, APP_PATH } from './resolver'
import { Resolver } from 'vite' import { Resolver } from 'vite'
import { SiteData, HeadConfig, LocaleConfig } from '../../types/shared' import { SiteData, HeadConfig, LocaleConfig } from '../../types/shared'
export { resolveSiteDataByRoute } from '../shared/config' export { resolveSiteDataByRoute } from './shared/config'
const debug = require('debug')('vitepress:config') const debug = require('debug')('vitepress:config')

@ -1,10 +1,17 @@
{ {
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"compilerOptions": { "compilerOptions": {
"outDir": "../../dist", "baseUrl": ".",
"outDir": "../../dist/node",
"module": "commonjs", "module": "commonjs",
"lib": ["ESNext", "DOM"], "lib": ["ESNext", "DOM"],
"sourceMap": true "sourceMap": true,
"paths": {
"/@types/*": ["../../types/*"]
}
}, },
"include": [".", "../shared", "../../types/shared.d.ts"] "include": [
".",
"../../types/shared.d.ts"
]
} }

@ -1,4 +1,4 @@
import { SiteData } from '../../types/shared' import { SiteData } from '/@types/shared'
const inBrowser = typeof window !== 'undefined' const inBrowser = typeof window !== 'undefined'

@ -2,12 +2,12 @@
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"compilerOptions": { "compilerOptions": {
"baseUrl": ".", "baseUrl": ".",
"outDir": "../../dist/client/shared", "paths": {
"module": "esnext", "/@types/*": ["../../types/*"]
"lib": ["ESNext", "DOM"], }
}, },
"include": [ "include": [
".", ".",
"../../types/shared.d.ts", "../../types/shared.d.ts"
] ]
} }

Loading…
Cancel
Save