@typed/vite-plugin 0.13.0 → 0.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/resolveTypedConfig.d.ts +13 -1
- package/dist/cjs/resolveTypedConfig.d.ts.map +1 -1
- package/dist/cjs/resolveTypedConfig.js.map +1 -1
- package/dist/cjs/vite-plugin.d.ts +1 -1
- package/dist/cjs/vite-plugin.d.ts.map +1 -1
- package/dist/cjs/vite-plugin.js +43 -49
- package/dist/cjs/vite-plugin.js.map +1 -1
- package/dist/resolveTypedConfig.d.ts +13 -1
- package/dist/resolveTypedConfig.d.ts.map +1 -1
- package/dist/resolveTypedConfig.js.map +1 -1
- package/dist/tsconfig.cjs.build.tsbuildinfo +1 -1
- package/dist/vite-plugin.d.ts +1 -1
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +43 -49
- package/dist/vite-plugin.js.map +1 -1
- package/package.json +11 -8
- package/src/resolveTypedConfig.test.ts +1 -2
- package/src/resolveTypedConfig.ts +14 -1
- package/src/vite-plugin.ts +50 -60
- package/tsconfig.build.json +5 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/tsconfig.cjs.build.json +1 -5
- package/tsconfig.json +1 -5
- package/vite.config.js +3 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAa,MAAM,EAAE,YAAY,EAAc,MAAM,MAAM,CAAA;AAIvE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAEzD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,QAAQ,CAA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
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { existsSync
|
|
2
|
-
import {
|
|
3
|
-
import { basename, join, resolve } from 'path';
|
|
1
|
+
import { existsSync } from 'fs';
|
|
2
|
+
import { basename, join, relative, resolve } from 'path';
|
|
4
3
|
import { pipe } from '@effect/data/Function';
|
|
5
4
|
import * as Option from '@effect/data/Option';
|
|
6
|
-
import { Compiler, getRelativePath } from '@typed/compiler';
|
|
7
5
|
import glob from 'fast-glob';
|
|
6
|
+
import { visualizer } from 'rollup-plugin-visualizer';
|
|
8
7
|
import vavite from 'vavite';
|
|
9
8
|
import compression from 'vite-plugin-compression';
|
|
10
9
|
import tsconfigPaths from 'vite-tsconfig-paths';
|
|
@@ -12,24 +11,23 @@ import { PLUGIN_NAME } from './constants.js';
|
|
|
12
11
|
const cwd = process.cwd();
|
|
13
12
|
export default function makePlugin(pluginOptions) {
|
|
14
13
|
const options = resolveOptions(pluginOptions);
|
|
15
|
-
let
|
|
16
|
-
let
|
|
17
|
-
let isSsr = false;
|
|
14
|
+
// let devServer: ViteDevServer
|
|
15
|
+
// let isSsr = false
|
|
18
16
|
const plugins = [
|
|
19
17
|
tsconfigPaths({
|
|
20
18
|
projects: [options.tsConfig],
|
|
21
19
|
}),
|
|
20
|
+
visualizer({
|
|
21
|
+
emitFile: true,
|
|
22
|
+
filename: 'bundle-visualizer.html',
|
|
23
|
+
gzipSize: true,
|
|
24
|
+
brotliSize: true,
|
|
25
|
+
}),
|
|
22
26
|
...pipe(options.serverFilePath, Option.filter(() => !options.isStaticBuild), Option.map((serverEntry) => vavite({
|
|
23
27
|
serverEntry,
|
|
24
28
|
serveClientAssetsInDev: true,
|
|
25
29
|
})), Option.toArray),
|
|
26
30
|
];
|
|
27
|
-
const getCompiler = () => {
|
|
28
|
-
if (compiler) {
|
|
29
|
-
return compiler;
|
|
30
|
-
}
|
|
31
|
-
return (compiler = new Compiler(PLUGIN_NAME, options));
|
|
32
|
-
};
|
|
33
31
|
const virtualModulePlugin = {
|
|
34
32
|
name: PLUGIN_NAME,
|
|
35
33
|
get resolvedOptions() {
|
|
@@ -39,7 +37,7 @@ export default function makePlugin(pluginOptions) {
|
|
|
39
37
|
* Configures our production build using vavite
|
|
40
38
|
*/
|
|
41
39
|
config(config, env) {
|
|
42
|
-
isSsr = env.ssrBuild ?? false
|
|
40
|
+
// isSsr = env.ssrBuild ?? false
|
|
43
41
|
if (!config.root) {
|
|
44
42
|
config.root = options.sourceDirectory;
|
|
45
43
|
}
|
|
@@ -49,6 +47,7 @@ export default function makePlugin(pluginOptions) {
|
|
|
49
47
|
outDir: options.clientOutputDirectory,
|
|
50
48
|
rollupOptions: {
|
|
51
49
|
input: buildClientInput(options.htmlFiles),
|
|
50
|
+
external: ['happy-dom'],
|
|
52
51
|
},
|
|
53
52
|
};
|
|
54
53
|
const clientConfig = {
|
|
@@ -78,68 +77,56 @@ export default function makePlugin(pluginOptions) {
|
|
|
78
77
|
configResolved(config) {
|
|
79
78
|
// Ensure final options has the correct base path
|
|
80
79
|
Object.assign(options, { base: config.base });
|
|
81
|
-
getCompiler().parseInput(config.build.rollupOptions.input);
|
|
82
80
|
},
|
|
83
81
|
/**
|
|
84
82
|
* Configures our dev server to watch for changes to our input files
|
|
85
83
|
* and exposes the dev server to our compiler methods
|
|
86
84
|
*/
|
|
87
|
-
configureServer(server) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (event === 'change') {
|
|
91
|
-
getCompiler().handleFileChange(path, 'update', server);
|
|
92
|
-
}
|
|
93
|
-
else if (event === 'add') {
|
|
94
|
-
getCompiler().handleFileChange(path, 'create', server);
|
|
95
|
-
}
|
|
96
|
-
else if (event === 'unlink') {
|
|
97
|
-
getCompiler().handleFileChange(path, 'delete', server);
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
},
|
|
85
|
+
// configureServer(server) {
|
|
86
|
+
// devServer = server
|
|
87
|
+
// },
|
|
101
88
|
/**
|
|
102
89
|
* Handles file changes
|
|
103
90
|
*/
|
|
104
|
-
async watchChange(path, { event }) {
|
|
105
|
-
getCompiler().handleFileChange(path, event, devServer);
|
|
106
|
-
},
|
|
91
|
+
// async watchChange(path, { event }) {},
|
|
107
92
|
/**
|
|
108
93
|
* Type-check our project and fail the build if there are any errors.
|
|
109
94
|
* If successful, save our manifest to disk.
|
|
110
95
|
*/
|
|
111
|
-
async closeBundle() {
|
|
112
|
-
const { manifest, throwDiagnostics } = getCompiler();
|
|
113
|
-
// Throw any diagnostics that were collected during the build
|
|
114
|
-
throwDiagnostics();
|
|
115
|
-
if (Object.keys(manifest).length > 0 && !options.isStaticBuild) {
|
|
116
|
-
writeFileSync(resolve(isSsr ? options.serverOutputDirectory : options.clientOutputDirectory, 'typed-manifest.json'), JSON.stringify(manifest, null, 2) + EOL);
|
|
117
|
-
}
|
|
118
|
-
},
|
|
96
|
+
// async closeBundle() {},
|
|
119
97
|
/**
|
|
120
98
|
* Resolve and build our virtual modules
|
|
121
99
|
*/
|
|
122
|
-
async resolveId(id
|
|
123
|
-
|
|
100
|
+
async resolveId(id) {
|
|
101
|
+
if (id === 'typed:config') {
|
|
102
|
+
return id;
|
|
103
|
+
}
|
|
104
|
+
return null;
|
|
124
105
|
},
|
|
125
106
|
/**
|
|
126
107
|
* Load our virtual modules
|
|
127
108
|
*/
|
|
128
109
|
load(id) {
|
|
129
|
-
|
|
110
|
+
if (id === 'typed:config') {
|
|
111
|
+
return Object.entries(options).reduce((acc, [key, value]) => {
|
|
112
|
+
acc += `export const ${key} = ${JSON.stringify(value)}\n`;
|
|
113
|
+
return acc;
|
|
114
|
+
}, '');
|
|
115
|
+
}
|
|
116
|
+
return null;
|
|
130
117
|
},
|
|
131
118
|
/**
|
|
132
119
|
* Transorm TypeScript modules
|
|
133
120
|
*/
|
|
134
|
-
transform(text, id) {
|
|
135
|
-
|
|
136
|
-
},
|
|
121
|
+
// transform(text: string, id: string) {
|
|
122
|
+
// return getCompiler().transpileTsModule(text, id, devServer)
|
|
123
|
+
// },
|
|
137
124
|
/**
|
|
138
125
|
* Transform HTML files
|
|
139
126
|
*/
|
|
140
|
-
transformIndexHtml(html) {
|
|
141
|
-
|
|
142
|
-
},
|
|
127
|
+
// transformIndexHtml(html: string) {
|
|
128
|
+
// return getCompiler().transformHtml(html)
|
|
129
|
+
// },
|
|
143
130
|
};
|
|
144
131
|
plugins.push(virtualModulePlugin);
|
|
145
132
|
return plugins;
|
|
@@ -185,4 +172,11 @@ export function findHtmlFiles(directory, htmlFileGlobs, exclusions) {
|
|
|
185
172
|
export function buildClientInput(htmlFilePaths) {
|
|
186
173
|
return htmlFilePaths.reduce((acc, htmlFilePath) => ({ ...acc, [basename(htmlFilePath, '.html')]: htmlFilePath }), {});
|
|
187
174
|
}
|
|
175
|
+
function getRelativePath(from, to) {
|
|
176
|
+
const path = relative(from, to);
|
|
177
|
+
if (path.startsWith('.')) {
|
|
178
|
+
return path;
|
|
179
|
+
}
|
|
180
|
+
return './' + path;
|
|
181
|
+
}
|
|
188
182
|
//# sourceMappingURL=vite-plugin.js.map
|
package/dist/vite-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAExD,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,KAAK,MAAM,MAAM,qBAAqB,CAAA;AAC7C,OAAO,IAAI,MAAM,WAAW,CAAA;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACrD,OAAO,MAAM,MAAM,QAAQ,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AE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,CAAA;KAC5F;IAED,6DAA6D;IAC7D,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,EAAE;QACjE,GAAG,EAAE,SAAS;KACf,CAAC,CAAA;AACJ,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,aAAgC;IAC/D,OAAO,aAAa,CAAC,MAAM,CACzB,CAAC,GAAG,EAAE,YAAY,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EACpF,EAAE,CACH,CAAA;AACH,CAAC;AAED,SAAS,eAAe,CAAC,IAAY,EAAE,EAAU;IAC/C,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;IAE/B,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;QACxB,OAAO,IAAI,CAAA;KACZ;IAED,OAAO,IAAI,GAAG,IAAI,CAAA;AACpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typed/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -19,20 +19,23 @@
|
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@effect/data": "^0.
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"vavite": "^
|
|
26
|
-
"vite": "^4.
|
|
22
|
+
"@effect/data": "^0.16.0",
|
|
23
|
+
"fast-glob": "^3.3.0",
|
|
24
|
+
"rollup-plugin-visualizer": "^5.9.2",
|
|
25
|
+
"vavite": "^2.0.1",
|
|
26
|
+
"vite": "^4.4.5",
|
|
27
27
|
"vite-plugin-compression": "^0.5.1",
|
|
28
28
|
"vite-tsconfig-paths": "^4.2.0"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"vite-node": "^0.28.3"
|
|
32
32
|
},
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "dac206ae9c9c6762dd958ae95438aaee0e29baa6",
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"sideEffects": false
|
|
37
|
+
"sideEffects": false,
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"vitest": "0.33.0"
|
|
40
|
+
}
|
|
38
41
|
}
|
|
@@ -3,10 +3,9 @@ import { dirname, join } from 'path'
|
|
|
3
3
|
import { fileURLToPath } from 'url'
|
|
4
4
|
|
|
5
5
|
import { isSome, some } from '@effect/data/Option'
|
|
6
|
-
import type { ResolvedOptions } from '@typed/compiler'
|
|
7
6
|
import { describe, it } from 'vitest'
|
|
8
7
|
|
|
9
|
-
import { resolveTypedConfig } from './resolveTypedConfig.js'
|
|
8
|
+
import { ResolvedOptions, resolveTypedConfig } from './resolveTypedConfig.js'
|
|
10
9
|
|
|
11
10
|
const vitePluginSrcDirectory = dirname(fileURLToPath(import.meta.url))
|
|
12
11
|
const rootDirectory = dirname(dirname(dirname(vitePluginSrcDirectory)))
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { none, some, type Option } from '@effect/data/Option'
|
|
2
|
-
import type { ResolvedOptions } from '@typed/compiler'
|
|
3
2
|
import { resolveConfig } from 'vite'
|
|
4
3
|
|
|
5
4
|
import { PLUGIN_NAME } from './constants.js'
|
|
@@ -19,3 +18,17 @@ export async function resolveTypedConfig(
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
type ArgsOf<T> = T extends (...args: infer A) => any ? A : never
|
|
21
|
+
|
|
22
|
+
export interface ResolvedOptions {
|
|
23
|
+
readonly base: string
|
|
24
|
+
readonly clientOutputDirectory: string
|
|
25
|
+
readonly debug: boolean
|
|
26
|
+
readonly exclusions: readonly string[]
|
|
27
|
+
readonly htmlFiles: readonly string[]
|
|
28
|
+
readonly isStaticBuild: boolean
|
|
29
|
+
readonly saveGeneratedModules: boolean
|
|
30
|
+
readonly serverFilePath: Option<string>
|
|
31
|
+
readonly serverOutputDirectory: string
|
|
32
|
+
readonly sourceDirectory: string
|
|
33
|
+
readonly tsConfig: string
|
|
34
|
+
}
|
package/src/vite-plugin.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { existsSync
|
|
2
|
-
import {
|
|
3
|
-
import { basename, join, resolve } from 'path'
|
|
1
|
+
import { existsSync } from 'fs'
|
|
2
|
+
import { basename, join, relative, resolve } from 'path'
|
|
4
3
|
|
|
5
4
|
import { pipe } from '@effect/data/Function'
|
|
6
5
|
import * as Option from '@effect/data/Option'
|
|
7
|
-
import { Compiler, getRelativePath, type ResolvedOptions } from '@typed/compiler'
|
|
8
6
|
import glob from 'fast-glob'
|
|
7
|
+
import { visualizer } from 'rollup-plugin-visualizer'
|
|
9
8
|
import vavite from 'vavite'
|
|
10
|
-
import type { ConfigEnv, Plugin, PluginOption, UserConfig
|
|
9
|
+
import type { ConfigEnv, Plugin, PluginOption, UserConfig } from 'vite'
|
|
11
10
|
import compression from 'vite-plugin-compression'
|
|
12
11
|
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
13
12
|
|
|
14
13
|
import { PLUGIN_NAME } from './constants.js'
|
|
14
|
+
import { ResolvedOptions } from './resolveTypedConfig.js'
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* The Configuration for the Typed Plugin. All file paths can be relative to sourceDirectory or
|
|
@@ -75,14 +75,19 @@ export interface TypedVitePlugin extends Plugin {
|
|
|
75
75
|
|
|
76
76
|
export default function makePlugin(pluginOptions: PluginOptions): PluginOption[] {
|
|
77
77
|
const options: ResolvedOptions = resolveOptions(pluginOptions)
|
|
78
|
-
let
|
|
79
|
-
let
|
|
80
|
-
let isSsr = false
|
|
78
|
+
// let devServer: ViteDevServer
|
|
79
|
+
// let isSsr = false
|
|
81
80
|
|
|
82
81
|
const plugins: PluginOption[] = [
|
|
83
82
|
tsconfigPaths({
|
|
84
83
|
projects: [options.tsConfig],
|
|
85
84
|
}) as PluginOption,
|
|
85
|
+
visualizer({
|
|
86
|
+
emitFile: true,
|
|
87
|
+
filename: 'bundle-visualizer.html',
|
|
88
|
+
gzipSize: true,
|
|
89
|
+
brotliSize: true,
|
|
90
|
+
}),
|
|
86
91
|
...pipe(
|
|
87
92
|
options.serverFilePath,
|
|
88
93
|
Option.filter(() => !options.isStaticBuild),
|
|
@@ -96,14 +101,6 @@ export default function makePlugin(pluginOptions: PluginOptions): PluginOption[]
|
|
|
96
101
|
),
|
|
97
102
|
]
|
|
98
103
|
|
|
99
|
-
const getCompiler = () => {
|
|
100
|
-
if (compiler) {
|
|
101
|
-
return compiler
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return (compiler = new Compiler(PLUGIN_NAME, options))
|
|
105
|
-
}
|
|
106
|
-
|
|
107
104
|
const virtualModulePlugin: TypedVitePlugin = {
|
|
108
105
|
name: PLUGIN_NAME,
|
|
109
106
|
get resolvedOptions() {
|
|
@@ -113,7 +110,7 @@ export default function makePlugin(pluginOptions: PluginOptions): PluginOption[]
|
|
|
113
110
|
* Configures our production build using vavite
|
|
114
111
|
*/
|
|
115
112
|
config(config: UserConfig, env: ConfigEnv) {
|
|
116
|
-
isSsr = env.ssrBuild ?? false
|
|
113
|
+
// isSsr = env.ssrBuild ?? false
|
|
117
114
|
|
|
118
115
|
if (!config.root) {
|
|
119
116
|
config.root = options.sourceDirectory
|
|
@@ -125,6 +122,7 @@ export default function makePlugin(pluginOptions: PluginOptions): PluginOption[]
|
|
|
125
122
|
outDir: options.clientOutputDirectory,
|
|
126
123
|
rollupOptions: {
|
|
127
124
|
input: buildClientInput(options.htmlFiles),
|
|
125
|
+
external: ['happy-dom'],
|
|
128
126
|
},
|
|
129
127
|
}
|
|
130
128
|
|
|
@@ -168,83 +166,65 @@ export default function makePlugin(pluginOptions: PluginOptions): PluginOption[]
|
|
|
168
166
|
configResolved(config) {
|
|
169
167
|
// Ensure final options has the correct base path
|
|
170
168
|
Object.assign(options, { base: config.base })
|
|
171
|
-
|
|
172
|
-
getCompiler().parseInput(config.build.rollupOptions.input)
|
|
173
169
|
},
|
|
174
170
|
|
|
175
171
|
/**
|
|
176
172
|
* Configures our dev server to watch for changes to our input files
|
|
177
173
|
* and exposes the dev server to our compiler methods
|
|
178
174
|
*/
|
|
179
|
-
configureServer(server) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
server.watcher.on('all', (event, path) => {
|
|
183
|
-
if (event === 'change') {
|
|
184
|
-
getCompiler().handleFileChange(path, 'update', server)
|
|
185
|
-
} else if (event === 'add') {
|
|
186
|
-
getCompiler().handleFileChange(path, 'create', server)
|
|
187
|
-
} else if (event === 'unlink') {
|
|
188
|
-
getCompiler().handleFileChange(path, 'delete', server)
|
|
189
|
-
}
|
|
190
|
-
})
|
|
191
|
-
},
|
|
175
|
+
// configureServer(server) {
|
|
176
|
+
// devServer = server
|
|
177
|
+
// },
|
|
192
178
|
|
|
193
179
|
/**
|
|
194
180
|
* Handles file changes
|
|
195
181
|
*/
|
|
196
|
-
async watchChange(path, { event }) {
|
|
197
|
-
getCompiler().handleFileChange(path, event, devServer)
|
|
198
|
-
},
|
|
182
|
+
// async watchChange(path, { event }) {},
|
|
199
183
|
|
|
200
184
|
/**
|
|
201
185
|
* Type-check our project and fail the build if there are any errors.
|
|
202
186
|
* If successful, save our manifest to disk.
|
|
203
187
|
*/
|
|
204
|
-
async closeBundle() {
|
|
205
|
-
const { manifest, throwDiagnostics } = getCompiler()
|
|
206
|
-
|
|
207
|
-
// Throw any diagnostics that were collected during the build
|
|
208
|
-
throwDiagnostics()
|
|
209
|
-
|
|
210
|
-
if (Object.keys(manifest).length > 0 && !options.isStaticBuild) {
|
|
211
|
-
writeFileSync(
|
|
212
|
-
resolve(
|
|
213
|
-
isSsr ? options.serverOutputDirectory : options.clientOutputDirectory,
|
|
214
|
-
'typed-manifest.json',
|
|
215
|
-
),
|
|
216
|
-
JSON.stringify(manifest, null, 2) + EOL,
|
|
217
|
-
)
|
|
218
|
-
}
|
|
219
|
-
},
|
|
188
|
+
// async closeBundle() {},
|
|
220
189
|
|
|
221
190
|
/**
|
|
222
191
|
* Resolve and build our virtual modules
|
|
223
192
|
*/
|
|
224
|
-
async resolveId(id: string
|
|
225
|
-
|
|
193
|
+
async resolveId(id: string) {
|
|
194
|
+
if (id === 'typed:config') {
|
|
195
|
+
return id
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return null
|
|
226
199
|
},
|
|
227
200
|
|
|
228
201
|
/**
|
|
229
202
|
* Load our virtual modules
|
|
230
203
|
*/
|
|
231
204
|
load(id: string) {
|
|
232
|
-
|
|
205
|
+
if (id === 'typed:config') {
|
|
206
|
+
return Object.entries(options).reduce((acc, [key, value]) => {
|
|
207
|
+
acc += `export const ${key} = ${JSON.stringify(value)}\n`
|
|
208
|
+
return acc
|
|
209
|
+
}, '')
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
return null
|
|
233
213
|
},
|
|
234
214
|
|
|
235
215
|
/**
|
|
236
216
|
* Transorm TypeScript modules
|
|
237
217
|
*/
|
|
238
|
-
transform(text: string, id: string) {
|
|
239
|
-
|
|
240
|
-
},
|
|
218
|
+
// transform(text: string, id: string) {
|
|
219
|
+
// return getCompiler().transpileTsModule(text, id, devServer)
|
|
220
|
+
// },
|
|
241
221
|
|
|
242
222
|
/**
|
|
243
223
|
* Transform HTML files
|
|
244
224
|
*/
|
|
245
|
-
transformIndexHtml(html: string) {
|
|
246
|
-
|
|
247
|
-
},
|
|
225
|
+
// transformIndexHtml(html: string) {
|
|
226
|
+
// return getCompiler().transformHtml(html)
|
|
227
|
+
// },
|
|
248
228
|
}
|
|
249
229
|
|
|
250
230
|
plugins.push(virtualModulePlugin)
|
|
@@ -324,3 +304,13 @@ export function buildClientInput(htmlFilePaths: readonly string[]) {
|
|
|
324
304
|
{},
|
|
325
305
|
)
|
|
326
306
|
}
|
|
307
|
+
|
|
308
|
+
function getRelativePath(from: string, to: string) {
|
|
309
|
+
const path = relative(from, to)
|
|
310
|
+
|
|
311
|
+
if (path.startsWith('.')) {
|
|
312
|
+
return path
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return './' + path
|
|
316
|
+
}
|