@codedesignai/nextjs-live-edit-plugin 1.0.4 → 1.0.5
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/index.js +13 -46
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,8 +2,11 @@ const path = require('path');
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Next.js config wrapper that enables the live edit plugin.
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Uses Turbopack's built-in webpack loader support via turbopack.rules.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: Only Turbopack is supported. Adding a `webpack` key to the config
|
|
8
|
+
* causes hydration mismatches in Next.js 16 because the loader would only
|
|
9
|
+
* run on client-side builds, while server-rendered HTML has no data attributes.
|
|
7
10
|
*
|
|
8
11
|
* Usage in next.config.js (CommonJS):
|
|
9
12
|
*
|
|
@@ -26,7 +29,6 @@ const path = require('path');
|
|
|
26
29
|
*/
|
|
27
30
|
function withLiveEdit(nextConfig = {}, pluginOptions = {}) {
|
|
28
31
|
const sourceDirs = pluginOptions.sourceDirs || ['app', 'components', 'src'];
|
|
29
|
-
const projectRoot = pluginOptions.projectRoot || process.cwd();
|
|
30
32
|
|
|
31
33
|
// Only add source mapping in development mode
|
|
32
34
|
if (process.env.NODE_ENV === 'production') {
|
|
@@ -34,67 +36,32 @@ function withLiveEdit(nextConfig = {}, pluginOptions = {}) {
|
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
const loaderPath = path.resolve(__dirname, 'source-mapper-loader.js');
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
39
|
+
const loaderConfig = {
|
|
40
|
+
loader: loaderPath,
|
|
41
|
+
options: {
|
|
42
|
+
sourceDirs,
|
|
43
|
+
projectRoot: process.cwd(),
|
|
44
|
+
},
|
|
40
45
|
};
|
|
41
46
|
|
|
42
|
-
// Preserve the user's existing webpack function if they have one
|
|
43
|
-
const existingWebpack = nextConfig.webpack;
|
|
44
|
-
|
|
45
47
|
// Merge with existing turbopack config
|
|
46
48
|
const existingTurbopack = nextConfig.turbopack || {};
|
|
47
49
|
const existingRules = existingTurbopack.rules || {};
|
|
48
50
|
|
|
49
|
-
const turbopackLoaderConfig = {
|
|
50
|
-
loader: loaderPath,
|
|
51
|
-
options: loaderOptions,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
51
|
return {
|
|
55
52
|
...nextConfig,
|
|
56
|
-
|
|
57
|
-
// ── Turbopack (next dev --turbopack) ──────────────────────────────
|
|
58
53
|
turbopack: {
|
|
59
54
|
...existingTurbopack,
|
|
60
55
|
rules: {
|
|
61
56
|
...existingRules,
|
|
62
57
|
'*.jsx': {
|
|
63
|
-
loaders: [
|
|
58
|
+
loaders: [loaderConfig],
|
|
64
59
|
},
|
|
65
60
|
'*.tsx': {
|
|
66
|
-
loaders: [
|
|
61
|
+
loaders: [loaderConfig],
|
|
67
62
|
},
|
|
68
63
|
},
|
|
69
64
|
},
|
|
70
|
-
|
|
71
|
-
// ── Webpack (next dev without --turbopack) ───────────────────────
|
|
72
|
-
webpack: (config, webpackOptions) => {
|
|
73
|
-
// Only add to client-side builds (server components don't render in browser)
|
|
74
|
-
if (!webpackOptions.isServer) {
|
|
75
|
-
// Resolve source directories to absolute paths for the webpack include filter
|
|
76
|
-
const includePaths = sourceDirs.map(dir => path.resolve(projectRoot, dir));
|
|
77
|
-
|
|
78
|
-
config.module.rules.push({
|
|
79
|
-
test: /\.(jsx|tsx)$/,
|
|
80
|
-
include: includePaths,
|
|
81
|
-
enforce: 'pre',
|
|
82
|
-
use: [
|
|
83
|
-
{
|
|
84
|
-
loader: loaderPath,
|
|
85
|
-
options: loaderOptions,
|
|
86
|
-
},
|
|
87
|
-
],
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Chain with the user's existing webpack config if present
|
|
92
|
-
if (typeof existingWebpack === 'function') {
|
|
93
|
-
return existingWebpack(config, webpackOptions);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return config;
|
|
97
|
-
},
|
|
98
65
|
};
|
|
99
66
|
}
|
|
100
67
|
|