@codedesignai/nextjs-live-edit-plugin 1.0.0 → 1.0.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.
Files changed (2) hide show
  1. package/index.js +32 -28
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -2,6 +2,7 @@ const path = require('path');
2
2
 
3
3
  /**
4
4
  * Next.js config wrapper that enables the live edit plugin.
5
+ * Uses Turbopack's built-in webpack loader support via turbopack.rules.
5
6
  *
6
7
  * Usage in next.config.js (CommonJS):
7
8
  *
@@ -25,37 +26,40 @@ const path = require('path');
25
26
  function withLiveEdit(nextConfig = {}, pluginOptions = {}) {
26
27
  const sourceDirs = pluginOptions.sourceDirs || ['app', 'components', 'src'];
27
28
 
28
- return {
29
- ...nextConfig,
30
- webpack(config, context) {
31
- const { dev, isServer } = context;
29
+ // Only add source mapping in development mode
30
+ if (process.env.NODE_ENV === 'production') {
31
+ return nextConfig;
32
+ }
32
33
 
33
- // Only add the source mapper in development mode and for client builds
34
- // (source mapping attributes are only needed in the browser)
35
- if (dev && !isServer) {
36
- // Add our source mapper loader for JSX/TSX files
37
- config.module.rules.push({
38
- test: /\.(jsx|tsx)$/,
39
- // Only process files in the configured source directories
40
- include: sourceDirs.map(dir => path.resolve(process.cwd(), dir)),
41
- use: [
42
- {
43
- loader: path.resolve(__dirname, 'source-mapper-loader.js'),
44
- options: {
45
- sourceDirs,
46
- projectRoot: process.cwd(),
47
- },
48
- },
49
- ],
50
- });
51
- }
34
+ const loaderPath = path.resolve(__dirname, 'source-mapper-loader.js');
35
+ const loaderConfig = {
36
+ loader: loaderPath,
37
+ options: {
38
+ sourceDirs,
39
+ projectRoot: process.cwd(),
40
+ },
41
+ };
52
42
 
53
- // Call the user's webpack config if they provided one
54
- if (typeof nextConfig.webpack === 'function') {
55
- return nextConfig.webpack(config, context);
56
- }
43
+ // Merge with existing turbopack config
44
+ const existingTurbopack = nextConfig.turbopack || {};
45
+ const existingRules = existingTurbopack.rules || {};
57
46
 
58
- return config;
47
+ return {
48
+ ...nextConfig,
49
+ turbopack: {
50
+ ...existingTurbopack,
51
+ rules: {
52
+ ...existingRules,
53
+ // Apply our source mapper loader to JSX and TSX files
54
+ '*.jsx': {
55
+ loaders: [loaderConfig],
56
+ as: '*.jsx',
57
+ },
58
+ '*.tsx': {
59
+ loaders: [loaderConfig],
60
+ as: '*.tsx',
61
+ },
62
+ },
59
63
  },
60
64
  };
61
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codedesignai/nextjs-live-edit-plugin",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Next.js plugin for live editing React components with AST-powered source mapping",
5
5
  "main": "index.js",
6
6
  "exports": {