@typestyles/next 0.5.9 → 0.6.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/build.cjs +8 -5
- package/dist/build.js +9 -6
- package/package.json +3 -3
- package/src/build.test.ts +37 -0
- package/src/build.ts +10 -1
package/dist/build.cjs
CHANGED
|
@@ -69,11 +69,14 @@ function withTypestylesExtract(nextConfig = {}, options = {}) {
|
|
|
69
69
|
} } : {},
|
|
70
70
|
webpack(config, context) {
|
|
71
71
|
const nextWebpack = typeof nextConfig.webpack === "function" ? nextConfig.webpack(config, context) : config;
|
|
72
|
-
if (disableClientRuntime && !context.isServer)
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
if (disableClientRuntime && !context.isServer) {
|
|
73
|
+
try {
|
|
74
|
+
const webpackLib = (0, node_module.createRequire)((0, node_path.join)(projectRoot, "package.json"))("webpack");
|
|
75
|
+
nextWebpack.plugins.push(new webpackLib.DefinePlugin({ __TYPESTYLES_RUNTIME_DISABLED__: JSON.stringify("true") }));
|
|
76
|
+
} catch {
|
|
77
|
+
console.warn("[@typestyles/next/build] Could not load webpack; client bundles may still inject <style>.");
|
|
78
|
+
}
|
|
79
|
+
nextWebpack.plugins.push(new _typestyles_build_runner.ZeroRuntimeSheetWebpackPlugin());
|
|
77
80
|
}
|
|
78
81
|
return nextWebpack;
|
|
79
82
|
}
|
package/dist/build.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createRequire } from "node:module";
|
|
2
|
-
import { DEFAULT_EXTRACT_MODULE_CANDIDATES, VerifyTypestylesBuildError, buildManifestV2, collectAndWriteRouteCss, discoverDefaultExtractModules, discoverDefaultExtractModules as discoverDefaultExtractModules$1, getRouteCss, verifyTypestylesBuild } from "@typestyles/build-runner";
|
|
2
|
+
import { DEFAULT_EXTRACT_MODULE_CANDIDATES, VerifyTypestylesBuildError, ZeroRuntimeSheetWebpackPlugin, buildManifestV2, collectAndWriteRouteCss, discoverDefaultExtractModules, discoverDefaultExtractModules as discoverDefaultExtractModules$1, getRouteCss, verifyTypestylesBuild } from "@typestyles/build-runner";
|
|
3
3
|
import { existsSync } from "node:fs";
|
|
4
4
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -68,11 +68,14 @@ function withTypestylesExtract(nextConfig = {}, options = {}) {
|
|
|
68
68
|
} } : {},
|
|
69
69
|
webpack(config, context) {
|
|
70
70
|
const nextWebpack = typeof nextConfig.webpack === "function" ? nextConfig.webpack(config, context) : config;
|
|
71
|
-
if (disableClientRuntime && !context.isServer)
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
if (disableClientRuntime && !context.isServer) {
|
|
72
|
+
try {
|
|
73
|
+
const webpackLib = createRequire(join(projectRoot, "package.json"))("webpack");
|
|
74
|
+
nextWebpack.plugins.push(new webpackLib.DefinePlugin({ __TYPESTYLES_RUNTIME_DISABLED__: JSON.stringify("true") }));
|
|
75
|
+
} catch {
|
|
76
|
+
console.warn("[@typestyles/next/build] Could not load webpack; client bundles may still inject <style>.");
|
|
77
|
+
}
|
|
78
|
+
nextWebpack.plugins.push(new ZeroRuntimeSheetWebpackPlugin());
|
|
76
79
|
}
|
|
77
80
|
return nextWebpack;
|
|
78
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typestyles/next",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Next.js integration for typestyles SSR",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@typestyles/build-runner": "0.
|
|
71
|
+
"@typestyles/build-runner": "0.8.0"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"vitest": "5.0.5",
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
"typescript": "^6.0.0",
|
|
82
82
|
"webpack": "^5.97.1",
|
|
83
83
|
"vite-plus": "1.3.0",
|
|
84
|
-
"typestyles": "0.
|
|
84
|
+
"typestyles": "0.35.0"
|
|
85
85
|
},
|
|
86
86
|
"scripts": {
|
|
87
87
|
"build": "vp pack",
|
package/src/build.test.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { describe, it, expect, vi } from 'vite-plus/test';
|
|
5
5
|
import type { NextConfig } from 'next';
|
|
6
6
|
import type { Configuration } from 'webpack';
|
|
7
|
+
import { ZeroRuntimeSheetWebpackPlugin } from '@typestyles/build-runner';
|
|
7
8
|
import { withTypestyles, withTypestylesExtract } from './build';
|
|
8
9
|
|
|
9
10
|
type WebpackContext = Parameters<NonNullable<NextConfig['webpack']>>[1];
|
|
@@ -47,6 +48,42 @@ describe('withTypestylesExtract', () => {
|
|
|
47
48
|
expect(hasDefine).toBe(true);
|
|
48
49
|
});
|
|
49
50
|
|
|
51
|
+
it('adds the zero-runtime sheet plugin only on client bundles', async () => {
|
|
52
|
+
const merged = withTypestylesExtract({});
|
|
53
|
+
const webpackHook = merged.webpack;
|
|
54
|
+
if (typeof webpackHook !== 'function') {
|
|
55
|
+
throw new Error('expected webpack hook');
|
|
56
|
+
}
|
|
57
|
+
const hasPlugin = (config: Configuration): boolean =>
|
|
58
|
+
(config.plugins ?? []).some((p) => p instanceof ZeroRuntimeSheetWebpackPlugin);
|
|
59
|
+
|
|
60
|
+
const client = webpackHook(
|
|
61
|
+
{ plugins: [] } as Configuration,
|
|
62
|
+
{ isServer: false } as WebpackContext,
|
|
63
|
+
);
|
|
64
|
+
expect(hasPlugin(client)).toBe(true);
|
|
65
|
+
expect(client.resolve?.alias).toBeUndefined();
|
|
66
|
+
|
|
67
|
+
const server = webpackHook(
|
|
68
|
+
{ plugins: [] } as Configuration,
|
|
69
|
+
{ isServer: true } as WebpackContext,
|
|
70
|
+
);
|
|
71
|
+
expect(hasPlugin(server)).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('leaves existing resolve aliases untouched', () => {
|
|
75
|
+
const merged = withTypestylesExtract({});
|
|
76
|
+
const webpackHook = merged.webpack;
|
|
77
|
+
if (typeof webpackHook !== 'function') {
|
|
78
|
+
throw new Error('expected webpack hook');
|
|
79
|
+
}
|
|
80
|
+
const preserved = webpackHook(
|
|
81
|
+
{ plugins: [], resolve: { alias: { '@typestyles/vite': '/abs/vite.js' } } } as Configuration,
|
|
82
|
+
{ isServer: false } as WebpackContext,
|
|
83
|
+
);
|
|
84
|
+
expect(preserved.resolve?.alias).toEqual({ '@typestyles/vite': '/abs/vite.js' });
|
|
85
|
+
});
|
|
86
|
+
|
|
50
87
|
it('applies extract in production when a convention entry exists under root', () => {
|
|
51
88
|
const dir = mkdtempSync(join(tmpdir(), 'typestyles-next-cwd-'));
|
|
52
89
|
mkdirSync(join(dir, 'styles'), { recursive: true });
|
package/src/build.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
buildManifestV2,
|
|
8
8
|
collectAndWriteRouteCss,
|
|
9
9
|
discoverDefaultExtractModules,
|
|
10
|
+
ZeroRuntimeSheetWebpackPlugin,
|
|
10
11
|
type TypestylesExtractManifestV1,
|
|
11
12
|
type TypestylesExtractManifestV2,
|
|
12
13
|
} from '@typestyles/build-runner';
|
|
@@ -184,7 +185,8 @@ export function withTypestyles(
|
|
|
184
185
|
/**
|
|
185
186
|
* Merge Next.js config so client bundles use pre-extracted CSS only (no runtime `<style>` injection).
|
|
186
187
|
*
|
|
187
|
-
* - **Webpack**: adds `DefinePlugin` for `__TYPESTYLES_RUNTIME_DISABLED__` on client bundles
|
|
188
|
+
* - **Webpack**: adds `DefinePlugin` for `__TYPESTYLES_RUNTIME_DISABLED__` on client bundles and
|
|
189
|
+
* resolves `typestyles` → `typestyles/core` (pure, name-only build — no CSS runtime in the client).
|
|
188
190
|
* - **Turbopack** (`next dev --turbo` / Turbopack production): webpack hooks do not run; the same
|
|
189
191
|
* `next.config` `env` entry `NEXT_PUBLIC_TYPESTYLES_RUNTIME_DISABLED` is merged so the client
|
|
190
192
|
* bundle still disables runtime insertion (see `typestyles` `sheet` implementation).
|
|
@@ -228,6 +230,13 @@ export function withTypestylesExtract(
|
|
|
228
230
|
'[@typestyles/next/build] Could not load webpack; client bundles may still inject <style>.',
|
|
229
231
|
);
|
|
230
232
|
}
|
|
233
|
+
|
|
234
|
+
// Zero-runtime: redirect typestyles' `sheet` module to its no-op
|
|
235
|
+
// sibling. Class names / data attributes are computed identically; the
|
|
236
|
+
// CSS insertion runtime, stylesheet state, and DOM plumbing never enter
|
|
237
|
+
// the client graph. Server bundles keep the real runtime (SSR
|
|
238
|
+
// collection / route CSS depends on it).
|
|
239
|
+
nextWebpack.plugins.push(new ZeroRuntimeSheetWebpackPlugin() as never);
|
|
231
240
|
}
|
|
232
241
|
|
|
233
242
|
return nextWebpack;
|