fix build errors in frontend-embed caused by vite not respecting the tsconfig setting
This commit is contained in:
parent
2b3fb2ef9f
commit
d18ec3ac2d
7 changed files with 81 additions and 27 deletions
1
packages/frontend-embed/.gitignore
vendored
1
packages/frontend-embed/.gitignore
vendored
|
|
@ -1 +1,2 @@
|
|||
/storybook-static
|
||||
tsconfig.json.bak
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ export default [
|
|||
parserOptions: {
|
||||
extraFileExtensions: ['.vue'],
|
||||
parser: tsParser,
|
||||
project: ['./tsconfig.vue.json'],
|
||||
project: ['tsconfig.vue.json'],
|
||||
sourceType: 'module',
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
|
|
@ -99,11 +99,31 @@ export default [
|
|||
},
|
||||
},
|
||||
{
|
||||
files: ['*.js', '*.ts'],
|
||||
files: [
|
||||
'*.js',
|
||||
'*.ts',
|
||||
'lib/**/*.ts',
|
||||
'lib/**/*.js',
|
||||
'scripts/**/*.ts',
|
||||
'scripts/**/*.js',
|
||||
'scripts/**/*.mjs',
|
||||
'scripts/**/*.cjs',
|
||||
],
|
||||
ignores: [
|
||||
'node_modules',
|
||||
'vue-shims.d.ts',
|
||||
'src',
|
||||
'test',
|
||||
'@types',
|
||||
'assets',
|
||||
],
|
||||
globals: {
|
||||
...globals.node,
|
||||
},
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
parser: tsParser,
|
||||
project: ['./tsconfig.scripts.json'],
|
||||
project: ['tsconfig.scripts.json'],
|
||||
sourceType: 'module',
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
|
|
@ -119,7 +139,7 @@ export default [
|
|||
'**/built/',
|
||||
'**/coverage/',
|
||||
'**/node_modules/',
|
||||
'vue-shims.d.ts'
|
||||
'vue-shims.d.ts',
|
||||
],
|
||||
},
|
||||
];
|
||||
|
|
|
|||
|
|
@ -3,8 +3,9 @@
|
|||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"watch": "vite",
|
||||
"build": "vite build",
|
||||
"watch": "node scripts/build.mjs --watch",
|
||||
"build": "node scripts/build.mjs",
|
||||
"build:pre": "pnpm run --filter misskey-js build && pnpm run --filter sw build && pnpm run --filter frontend_shared build",
|
||||
"typecheck-all": "pnpm run --no-bail typecheck:vue && pnpm run --no-bail typecheck:scripts",
|
||||
"typecheck": "pnpm run typecheck:vue && pnpm run typecheck:scripts",
|
||||
"typecheck:vue": "vue-tsc -p tsconfig.vue.json --noEmit",
|
||||
|
|
|
|||
37
packages/frontend-embed/scripts/build.mjs
Normal file
37
packages/frontend-embed/scripts/build.mjs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/**
|
||||
* Hot-swaps tsconfig files to work around vite limitations.
|
||||
* Based on idea from https://github.com/vitejs/vite/discussions/8483#discussioncomment-6830634
|
||||
*/
|
||||
|
||||
import nodeFs from 'node:fs/promises';
|
||||
import nodePath from 'node:path';
|
||||
import { execa } from 'execa';
|
||||
|
||||
const rootDir = nodePath.resolve(import.meta.dirname, '../');
|
||||
const tsConfig = nodePath.resolve(rootDir, 'tsconfig.json');
|
||||
const tsConfigBak = nodePath.resolve(rootDir, 'tsconfig.json.bak');
|
||||
const tsConfigVue = nodePath.resolve(rootDir, 'tsconfig.vue.json');
|
||||
|
||||
const mode = process.argv.slice(2).includes('--watch') ? 'watch' : 'build';
|
||||
|
||||
console.log('Staging tsconfig.vue.json as tsconfig.json...');
|
||||
await nodeFs.rename(tsConfig, tsConfigBak);
|
||||
await nodeFs.copyFile(tsConfigVue, tsConfig);
|
||||
|
||||
try {
|
||||
console.log('Starting vite...')
|
||||
await execa(
|
||||
'vite',
|
||||
mode === 'build'
|
||||
? ['build']
|
||||
: [],
|
||||
{
|
||||
stdout: process.stdout,
|
||||
stderr: process.stderr,
|
||||
},
|
||||
);
|
||||
} finally {
|
||||
console.log('Restoring original tsconfig.json...');
|
||||
await nodeFs.rm(tsConfig);
|
||||
await nodeFs.rename(tsConfigBak, tsConfig);
|
||||
}
|
||||
|
|
@ -1,23 +1,20 @@
|
|||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "../shared/tsconfig.scripts.jsonc",
|
||||
"compilerOptions": {
|
||||
"typeRoots": [
|
||||
"./@types",
|
||||
"./node_modules/@vue-macros",
|
||||
"./node_modules/@types",
|
||||
"./node_modules"
|
||||
],
|
||||
"types": [
|
||||
"vite/client",
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"*.js",
|
||||
"*.ts"
|
||||
"*.ts",
|
||||
"scripts/**/*.ts",
|
||||
"scripts/**/*.js",
|
||||
"scripts/**/*.mjs",
|
||||
"scripts/**/*.cjs"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"vue-shims.d.ts"
|
||||
"vue-shims.d.ts",
|
||||
"src",
|
||||
"test",
|
||||
"@types",
|
||||
"assets"
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,12 @@
|
|||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "../shared/tsconfig.web.jsonc",
|
||||
"compilerOptions": {
|
||||
"noImplicitAny": false,
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"experimentalDecorators": true,
|
||||
"resolveJsonModule": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"paths": {
|
||||
"@/*": ["./src/*"],
|
||||
"@@/*": ["../frontend-shared/*"]
|
||||
|
|
|
|||
|
|
@ -6,9 +6,7 @@ import { localesVersion } from '../../locales/version.js';
|
|||
import locales from '../../locales/index.js';
|
||||
import meta from '../../package.json' with { type: 'json' };
|
||||
import packageInfo from './package.json' with { type: 'json' };
|
||||
import tsconfigVue from './tsconfig.vue.json' with { type: 'json' };
|
||||
import pluginJson5 from './vite.json5.js';
|
||||
import type { TsconfigRaw } from 'esbuild';
|
||||
|
||||
const extensions = ['.ts', '.tsx', '.js', '.jsx', '.mjs', '.json', '.json5', '.svg', '.sass', '.scss', '.css', '.vue'];
|
||||
|
||||
|
|
@ -117,12 +115,6 @@ export function getConfig(): UserConfig {
|
|||
__VUE_PROD_DEVTOOLS__: false,
|
||||
},
|
||||
|
||||
esbuild: {
|
||||
// https://github.com/vitejs/vite/discussions/8483#discussioncomment-14485974
|
||||
// https://esbuild.github.io/api/#tsconfig-raw
|
||||
tsconfigRaw: tsconfigVue as TsconfigRaw,
|
||||
},
|
||||
|
||||
build: {
|
||||
target: [
|
||||
'chrome116',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue