Skip to content

Commit 85055d1

Browse files
authored
fix(fullstack): enable emitAssets by default (#1176)
1 parent a3a86f3 commit 85055d1

File tree

6 files changed

+18
-16
lines changed

6 files changed

+18
-16
lines changed

packages/fullstack/examples/basic/vite.config.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import fullstack, {
22
reactHmrPreamblePlugin,
33
} from "@hiogawa/vite-plugin-fullstack";
44
// import inspect from "vite-plugin-inspect";
5-
// import { cloudflare } from "@cloudflare/vite-plugin";
65
import react from "@vitejs/plugin-react";
76
import { defineConfig } from "vite";
87

@@ -20,15 +19,14 @@ export default defineConfig((_env) => ({
2019
outDir: "./dist/client",
2120
},
2221
// excplit rollupOptions.input is not necessary,
23-
// but `optimizeDeps.entries` is desired to set.
22+
// but `optimizeDeps.entries` is still desired to set.
2423
optimizeDeps: {
2524
entries: ["./src/entry.client.tsx"],
2625
},
2726
},
2827
ssr: {
2928
build: {
3029
outDir: "./dist/ssr",
31-
emitAssets: true,
3230
rollupOptions: {
3331
input: {
3432
index: "./src/entry.server.tsx",
@@ -39,8 +37,6 @@ export default defineConfig((_env) => ({
3937
},
4038
builder: {
4139
async buildApp(builder) {
42-
// NOTE
43-
// dynamically adding entry is supported only when building ssr -> client
4440
await builder.build(builder.environments["ssr"]!);
4541
await builder.build(builder.environments["client"]!);
4642
},

packages/fullstack/examples/cloudflare/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export default defineConfig((_env) => ({
3131
ssr: {
3232
build: {
3333
outDir: "./dist/ssr",
34-
emitAssets: true,
3534
rollupOptions: {
3635
input: {
3736
index: "./src/entry.server.tsx",

packages/fullstack/examples/island/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default defineConfig((_env) => ({
2626
ssr: {
2727
build: {
2828
outDir: "./dist/ssr",
29-
emitAssets: true,
3029
rollupOptions: {
3130
input: {
3231
index: "./src/entry.server.tsx",

packages/fullstack/examples/react-router/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ export default defineConfig((_env) => ({
2929
ssr: {
3030
build: {
3131
outDir: "./dist/ssr",
32-
emitAssets: true,
3332
rollupOptions: {
3433
input: {
3534
index: "./src/framework/entry.server.tsx",

packages/fullstack/examples/vue-router/vite.config.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ export default defineConfig((_env) => ({
2626
ssr: {
2727
build: {
2828
outDir: "./dist/ssr",
29-
emitAssets: true,
3029
rollupOptions: {
3130
input: {
3231
index: "./src/framework/entry.server.tsx",

packages/fullstack/src/plugin.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ type FullstackPluginOptions = {
3636
* @default true
3737
*/
3838
serverHandler?: boolean;
39-
// /**
40-
// * @default ["ssr"]
41-
// */
42-
// serverEnvironments?: string[];
39+
/**
40+
* @default ["ssr"]
41+
*/
42+
serverEnvironments?: string[];
4343
};
4444

4545
type ImportAssetsMeta = {
@@ -68,8 +68,9 @@ export function serverHandlerPlugin(
6868
};
6969
},
7070
configureServer(server) {
71-
assert(isRunnableDevEnvironment(server.environments.ssr));
72-
const environment = server.environments.ssr;
71+
const name = (pluginOpts?.serverEnvironments ?? ["ssr"])[0]!;
72+
const environment = server.environments[name]!;
73+
assert(isRunnableDevEnvironment(environment));
7374
const runner = environment.runner;
7475
return () => {
7576
server.middlewares.use(async (req, res, next) => {
@@ -88,7 +89,7 @@ export function serverHandlerPlugin(
8889
];
8990
}
9091

91-
export function assetsPlugin(_pluginOpts?: FullstackPluginOptions): Plugin[] {
92+
export function assetsPlugin(pluginOpts?: FullstackPluginOptions): Plugin[] {
9293
let server: ViteDevServer;
9394
let resolvedConfig: ResolvedConfig;
9495
const importAssetsMetaMap: {
@@ -107,6 +108,15 @@ export function assetsPlugin(_pluginOpts?: FullstackPluginOptions): Plugin[] {
107108
configResolved(config) {
108109
resolvedConfig = config;
109110
},
111+
configEnvironment(name) {
112+
if (pluginOpts?.serverEnvironments?.includes(name)) {
113+
return {
114+
build: {
115+
emitAssets: true,
116+
},
117+
};
118+
}
119+
},
110120
/**
111121
* [Transform input]
112122
* const assets = import.meta.vite.assets(...)

0 commit comments

Comments
 (0)