@eventuras/vite-config 0.3.0 → 0.3.1
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/react-lib.js +15 -6
- package/package.json +1 -1
package/dist/react-lib.js
CHANGED
|
@@ -13,6 +13,14 @@ import { getRuntimeDependencyExternals, NODE_BUILTINS_EXTERNAL } from './externa
|
|
|
13
13
|
* consumers never need.
|
|
14
14
|
*/
|
|
15
15
|
const requireFromHere = createRequire(import.meta.url);
|
|
16
|
+
/**
|
|
17
|
+
* Strip leading whitespace and any interleaved mix of line and block comments,
|
|
18
|
+
* so a directive check sees the first real token. Sequential per-style passes
|
|
19
|
+
* miss mixed orders (a line comment, then a block comment, then the directive).
|
|
20
|
+
*/
|
|
21
|
+
function stripLeadingComments(code) {
|
|
22
|
+
return code.replace(/^(?:\s+|\/\*[\s\S]*?\*\/\s*|\/\/.*(?:\r?\n|$)\s*)+/, '');
|
|
23
|
+
}
|
|
16
24
|
/**
|
|
17
25
|
* Plugin to preserve 'use client' directives in React Server Components.
|
|
18
26
|
* This ensures client-side code is properly marked when building for Next.js.
|
|
@@ -30,18 +38,19 @@ function preserveUseClient() {
|
|
|
30
38
|
try {
|
|
31
39
|
const content = fs.readFileSync(id, 'utf-8');
|
|
32
40
|
// Remove leading comments to check for 'use client'
|
|
33
|
-
const withoutComments = content
|
|
34
|
-
|
|
35
|
-
.
|
|
36
|
-
return (withoutComments.trimStart().startsWith("'use client'") ||
|
|
37
|
-
withoutComments.trimStart().startsWith('"use client"'));
|
|
41
|
+
const withoutComments = stripLeadingComments(content);
|
|
42
|
+
return (withoutComments.startsWith("'use client'") ||
|
|
43
|
+
withoutComments.startsWith('"use client"'));
|
|
38
44
|
}
|
|
39
45
|
catch {
|
|
40
46
|
return false;
|
|
41
47
|
}
|
|
42
48
|
});
|
|
43
49
|
if (hasClientDirective) {
|
|
44
|
-
|
|
50
|
+
// Ignore leading banner/license comments (e.g. Rollup's
|
|
51
|
+
// output.banner) when checking for the directive, so we don't
|
|
52
|
+
// prepend a duplicate above a directive that's already there.
|
|
53
|
+
const codeStart = stripLeadingComments(chunkData.code);
|
|
45
54
|
if (!codeStart.startsWith("'use client'") && !codeStart.startsWith('"use client"')) {
|
|
46
55
|
chunkData.code = `'use client';\n${chunkData.code}`;
|
|
47
56
|
}
|