@jahia/vite-plugin 0.5.1 → 0.5.3

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/index.js CHANGED
@@ -103,6 +103,19 @@ function buildSuccessPlugin(callback) {
103
103
  };
104
104
  }
105
105
  function jahia(options = {}) {
106
+ const clientEntries = globSync(options.client?.input?.glob ?? "**/*.jsx", {
107
+ cwd: options.client?.input?.dir ?? "./src/client/",
108
+ absolute: true
109
+ });
110
+ if (clientEntries.length === 0) {
111
+ console.warn(
112
+ `${styleText("yellowBright", "[@jahia/vite-plugin] Skipping client build because there are no entry files...")}
113
+ \u2022 If this is the intended behavior, you can safely ignore this message
114
+ \u2022 Otherwise, ensure that your client files are properly configured in the plugin options
115
+ Client base directory: ${styleText("cyanBright", options.client?.input?.dir ?? "./src/client/ (default value)")}
116
+ Client glob pattern: ${styleText("cyanBright", String(options.client?.input?.glob ?? "**/*.jsx (default value)"))}`
117
+ );
118
+ }
106
119
  return {
107
120
  name: "@jahia/vite-plugin",
108
121
  /**
@@ -114,7 +127,7 @@ function jahia(options = {}) {
114
127
  * @see https://vite.dev/guide/api-plugin.html#config
115
128
  */
116
129
  config(config) {
117
- config.builder ??= {};
130
+ config.builder ??= { sharedConfigBuild: true };
118
131
  config.esbuild ??= { jsx: "automatic" };
119
132
  return {
120
133
  environments: {
@@ -122,10 +135,7 @@ function jahia(options = {}) {
122
135
  build: {
123
136
  lib: {
124
137
  // Single entry point for the client, all other files must be imported in this one
125
- entry: globSync(options.client?.input?.glob ?? "**/*.jsx", {
126
- cwd: options.client?.input?.dir ?? "./src/client/",
127
- absolute: true
128
- }),
138
+ entry: clientEntries,
129
139
  formats: ["es"]
130
140
  },
131
141
  rollupOptions: {
@@ -206,6 +216,9 @@ function jahia(options = {}) {
206
216
  }
207
217
  };
208
218
  },
219
+ configResolved(config) {
220
+ if (clientEntries.length === 0) delete config.environments.client;
221
+ },
209
222
  // Needed to run before Vite's default resolver
210
223
  enforce: "pre",
211
224
  resolveId(id, importer) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jahia/vite-plugin",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com:Jahia/javascript-modules.git",
package/pom.xml CHANGED
@@ -3,7 +3,7 @@
3
3
  <parent>
4
4
  <artifactId>javascript-modules</artifactId>
5
5
  <groupId>org.jahia.modules</groupId>
6
- <version>0.5.1</version>
6
+ <version>0.5.3</version>
7
7
  </parent>
8
8
  <artifactId>vite-plugin</artifactId>
9
9
  <name>Vite plugin for Jahia</name>
package/src/index.ts CHANGED
@@ -94,6 +94,21 @@ export default function jahia(
94
94
  watchCallback?: () => void | Promise<void>;
95
95
  } = {},
96
96
  ): PluginOption {
97
+ const clientEntries = globSync(options.client?.input?.glob ?? "**/*.jsx", {
98
+ cwd: options.client?.input?.dir ?? "./src/client/",
99
+ absolute: true,
100
+ });
101
+
102
+ if (clientEntries.length === 0) {
103
+ console.warn(
104
+ `${styleText("yellowBright", "[@jahia/vite-plugin] Skipping client build because there are no entry files...")}
105
+ • If this is the intended behavior, you can safely ignore this message
106
+ • Otherwise, ensure that your client files are properly configured in the plugin options
107
+ Client base directory: ${styleText("cyanBright", options.client?.input?.dir ?? "./src/client/ (default value)")}
108
+ Client glob pattern: ${styleText("cyanBright", String(options.client?.input?.glob ?? "**/*.jsx (default value)"))}`,
109
+ );
110
+ }
111
+
97
112
  return {
98
113
  name: "@jahia/vite-plugin",
99
114
 
@@ -108,7 +123,7 @@ export default function jahia(
108
123
  config(config) {
109
124
  // Mutate the configuration to set base settings if they are not already set
110
125
  // Build all environments https://vite.dev/guide/api-environment-frameworks.html#environments-during-build
111
- config.builder ??= {};
126
+ config.builder ??= { sharedConfigBuild: true };
112
127
 
113
128
  // Enable the modern JSX runtime
114
129
  config.esbuild ??= { jsx: "automatic" };
@@ -119,10 +134,7 @@ export default function jahia(
119
134
  build: {
120
135
  lib: {
121
136
  // Single entry point for the client, all other files must be imported in this one
122
- entry: globSync(options.client?.input?.glob ?? "**/*.jsx", {
123
- cwd: options.client?.input?.dir ?? "./src/client/",
124
- absolute: true,
125
- }),
137
+ entry: clientEntries,
126
138
  formats: ["es"],
127
139
  },
128
140
  rollupOptions: {
@@ -207,6 +219,11 @@ export default function jahia(
207
219
  };
208
220
  },
209
221
 
222
+ configResolved(config) {
223
+ // If there are no client entries, remove the client environment to prevent a build error
224
+ if (clientEntries.length === 0) delete config.environments.client;
225
+ },
226
+
210
227
  // Needed to run before Vite's default resolver
211
228
  enforce: "pre",
212
229
  resolveId(id, importer) {