@marko/vite 2.4.9 → 3.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.
package/README.md CHANGED
@@ -94,7 +94,7 @@ app.listen(3000);
94
94
 
95
95
  ### options.babelConfig
96
96
 
97
- You can manually override Marko's Babel configuration by passing a `babelConfig` object to the `@marko/vite` plugin. By default Babel's regular [config file resolution](https://babeljs.io/docs/en/config-files) will be used.
97
+ You can manually override Marko's Babel configuration by passing a `babelConfig` object to the `@marko/vite` plugin. If no babel configuration is specified, babel related config files will not be considered.
98
98
 
99
99
  ```javascript
100
100
  marko({
package/dist/index.js CHANGED
@@ -59,6 +59,13 @@ const htmlExt = ".html";
59
59
  const resolveOpts = { skipSelf: true };
60
60
  const cache = /* @__PURE__ */ new Map();
61
61
  const thisFile = typeof __filename === "string" ? __filename : (0, import_url.fileURLToPath)(import_meta.url);
62
+ const babelCaller = {
63
+ name: "@marko/vite",
64
+ supportsStaticESM: true,
65
+ supportsDynamicImport: true,
66
+ supportsTopLevelAwait: true,
67
+ supportsExportNamespaceFrom: true
68
+ };
62
69
  function markoPlugin(opts = {}) {
63
70
  let compiler;
64
71
  let { linked = true } = opts;
@@ -68,7 +75,7 @@ function markoPlugin(opts = {}) {
68
75
  let ssrConfig;
69
76
  let domConfig;
70
77
  let hydrateConfig;
71
- const resolveViteVirtualDep = (from, dep) => {
78
+ const resolveVirtualDependency = (from, dep) => {
72
79
  const query = `${virtualFileQuery}&id=${encodeURIComponent(
73
80
  normalizePath(dep.virtualPath)
74
81
  )}`;
@@ -105,7 +112,7 @@ function markoPlugin(opts = {}) {
105
112
  enforce: "pre",
106
113
  // Must be pre to allow us to resolve assets before vite.
107
114
  async config(config, env) {
108
- var _a;
115
+ var _a, _b, _c, _d, _e;
109
116
  compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
110
117
  runtimeId = opts.runtimeId;
111
118
  basePathVar = opts.basePathVar;
@@ -114,31 +121,36 @@ function markoPlugin(opts = {}) {
114
121
  runtimeId,
115
122
  sourceMaps: true,
116
123
  writeVersionComment: false,
117
- babelConfig: {
124
+ babelConfig: opts.babelConfig ? {
118
125
  ...opts.babelConfig,
119
- caller: {
126
+ caller: opts.babelConfig.caller ? {
120
127
  name: "@marko/vite",
121
128
  supportsStaticESM: true,
122
129
  supportsDynamicImport: true,
123
130
  supportsTopLevelAwait: true,
124
131
  supportsExportNamespaceFrom: true,
125
- ...(_a = opts.babelConfig) == null ? void 0 : _a.caller
126
- }
132
+ ...opts.babelConfig.caller
133
+ } : babelCaller
134
+ } : {
135
+ babelrc: false,
136
+ configFile: false,
137
+ browserslistConfigFile: false,
138
+ caller: babelCaller
127
139
  }
128
140
  };
129
141
  ssrConfig = {
130
142
  ...baseConfig,
131
- resolveVirtualDependency: resolveViteVirtualDep,
143
+ resolveVirtualDependency,
132
144
  output: "html"
133
145
  };
134
146
  domConfig = {
135
147
  ...baseConfig,
136
- resolveVirtualDependency: resolveViteVirtualDep,
148
+ resolveVirtualDependency,
137
149
  output: "dom"
138
150
  };
139
151
  hydrateConfig = {
140
152
  ...baseConfig,
141
- resolveVirtualDependency: resolveViteVirtualDep,
153
+ resolveVirtualDependency,
142
154
  output: "hydrate"
143
155
  };
144
156
  compiler.configure(baseConfig);
@@ -153,6 +165,13 @@ function markoPlugin(opts = {}) {
153
165
  );
154
166
  if (isTest) {
155
167
  linked = false;
168
+ if ((_b = (_a = config.test) == null ? void 0 : _a.environment) == null ? void 0 : _b.includes(
169
+ "dom"
170
+ )) {
171
+ config.resolve ?? (config.resolve = {});
172
+ (_c = config.resolve).conditions ?? (_c.conditions = []);
173
+ config.resolve.conditions.push("browser");
174
+ }
156
175
  }
157
176
  if (linked && !registeredTag) {
158
177
  const transformer = import_path.default.resolve(
@@ -219,13 +238,26 @@ function markoPlugin(opts = {}) {
219
238
  "Cannot use @marko/vite `basePathVar` with Vite's `renderBuiltUrl` option."
220
239
  );
221
240
  }
241
+ const assetsDir = ((_e = (_d = config.build) == null ? void 0 : _d.assetsDir) == null ? void 0 : _e.replace(/[/\\]$/, "")) ?? "assets";
242
+ const assetsDirLen = assetsDir.length;
243
+ const assetsDirEnd = assetsDirLen + 1;
244
+ const trimAssertsDir = (fileName) => {
245
+ if (fileName.startsWith(assetsDir)) {
246
+ switch (fileName[assetsDirLen]) {
247
+ case POSIX_SEP:
248
+ case WINDOWS_SEP:
249
+ return fileName.slice(assetsDirEnd);
250
+ }
251
+ }
252
+ return fileName;
253
+ };
222
254
  config.experimental.renderBuiltUrl = (fileName, { hostType, ssr: ssr2 }) => {
223
255
  switch (hostType) {
224
256
  case "html":
225
- return fileName;
257
+ return trimAssertsDir(fileName);
226
258
  case "js":
227
259
  return {
228
- runtime: `${ssr2 ? basePathVar : `$mbp${runtimeId ? `_${runtimeId}` : ""}`}+${JSON.stringify(fileName)}`
260
+ runtime: `${ssr2 ? basePathVar : `$mbp${runtimeId ? `_${runtimeId}` : ""}`}+${JSON.stringify(trimAssertsDir(fileName))}`
229
261
  };
230
262
  default:
231
263
  return { relative: true };
package/dist/index.mjs CHANGED
@@ -39,6 +39,13 @@ var htmlExt = ".html";
39
39
  var resolveOpts = { skipSelf: true };
40
40
  var cache = /* @__PURE__ */ new Map();
41
41
  var thisFile = typeof __filename === "string" ? __filename : fileURLToPath(import.meta.url);
42
+ var babelCaller = {
43
+ name: "@marko/vite",
44
+ supportsStaticESM: true,
45
+ supportsDynamicImport: true,
46
+ supportsTopLevelAwait: true,
47
+ supportsExportNamespaceFrom: true
48
+ };
42
49
  function markoPlugin(opts = {}) {
43
50
  let compiler;
44
51
  let { linked = true } = opts;
@@ -48,7 +55,7 @@ function markoPlugin(opts = {}) {
48
55
  let ssrConfig;
49
56
  let domConfig;
50
57
  let hydrateConfig;
51
- const resolveViteVirtualDep = (from, dep) => {
58
+ const resolveVirtualDependency = (from, dep) => {
52
59
  const query = `${virtualFileQuery}&id=${encodeURIComponent(
53
60
  normalizePath(dep.virtualPath)
54
61
  )}`;
@@ -85,7 +92,7 @@ function markoPlugin(opts = {}) {
85
92
  enforce: "pre",
86
93
  // Must be pre to allow us to resolve assets before vite.
87
94
  async config(config, env) {
88
- var _a;
95
+ var _a, _b, _c, _d, _e;
89
96
  compiler ?? (compiler = await import(opts.compiler || "@marko/compiler"));
90
97
  runtimeId = opts.runtimeId;
91
98
  basePathVar = opts.basePathVar;
@@ -94,31 +101,36 @@ function markoPlugin(opts = {}) {
94
101
  runtimeId,
95
102
  sourceMaps: true,
96
103
  writeVersionComment: false,
97
- babelConfig: {
104
+ babelConfig: opts.babelConfig ? {
98
105
  ...opts.babelConfig,
99
- caller: {
106
+ caller: opts.babelConfig.caller ? {
100
107
  name: "@marko/vite",
101
108
  supportsStaticESM: true,
102
109
  supportsDynamicImport: true,
103
110
  supportsTopLevelAwait: true,
104
111
  supportsExportNamespaceFrom: true,
105
- ...(_a = opts.babelConfig) == null ? void 0 : _a.caller
106
- }
112
+ ...opts.babelConfig.caller
113
+ } : babelCaller
114
+ } : {
115
+ babelrc: false,
116
+ configFile: false,
117
+ browserslistConfigFile: false,
118
+ caller: babelCaller
107
119
  }
108
120
  };
109
121
  ssrConfig = {
110
122
  ...baseConfig,
111
- resolveVirtualDependency: resolveViteVirtualDep,
123
+ resolveVirtualDependency,
112
124
  output: "html"
113
125
  };
114
126
  domConfig = {
115
127
  ...baseConfig,
116
- resolveVirtualDependency: resolveViteVirtualDep,
128
+ resolveVirtualDependency,
117
129
  output: "dom"
118
130
  };
119
131
  hydrateConfig = {
120
132
  ...baseConfig,
121
- resolveVirtualDependency: resolveViteVirtualDep,
133
+ resolveVirtualDependency,
122
134
  output: "hydrate"
123
135
  };
124
136
  compiler.configure(baseConfig);
@@ -133,6 +145,13 @@ function markoPlugin(opts = {}) {
133
145
  );
134
146
  if (isTest) {
135
147
  linked = false;
148
+ if ((_b = (_a = config.test) == null ? void 0 : _a.environment) == null ? void 0 : _b.includes(
149
+ "dom"
150
+ )) {
151
+ config.resolve ?? (config.resolve = {});
152
+ (_c = config.resolve).conditions ?? (_c.conditions = []);
153
+ config.resolve.conditions.push("browser");
154
+ }
136
155
  }
137
156
  if (linked && !registeredTag) {
138
157
  const transformer = path.resolve(
@@ -199,13 +218,26 @@ function markoPlugin(opts = {}) {
199
218
  "Cannot use @marko/vite `basePathVar` with Vite's `renderBuiltUrl` option."
200
219
  );
201
220
  }
221
+ const assetsDir = ((_e = (_d = config.build) == null ? void 0 : _d.assetsDir) == null ? void 0 : _e.replace(/[/\\]$/, "")) ?? "assets";
222
+ const assetsDirLen = assetsDir.length;
223
+ const assetsDirEnd = assetsDirLen + 1;
224
+ const trimAssertsDir = (fileName) => {
225
+ if (fileName.startsWith(assetsDir)) {
226
+ switch (fileName[assetsDirLen]) {
227
+ case POSIX_SEP:
228
+ case WINDOWS_SEP:
229
+ return fileName.slice(assetsDirEnd);
230
+ }
231
+ }
232
+ return fileName;
233
+ };
202
234
  config.experimental.renderBuiltUrl = (fileName, { hostType, ssr: ssr2 }) => {
203
235
  switch (hostType) {
204
236
  case "html":
205
- return fileName;
237
+ return trimAssertsDir(fileName);
206
238
  case "js":
207
239
  return {
208
- runtime: `${ssr2 ? basePathVar : `$mbp${runtimeId ? `_${runtimeId}` : ""}`}+${JSON.stringify(fileName)}`
240
+ runtime: `${ssr2 ? basePathVar : `$mbp${runtimeId ? `_${runtimeId}` : ""}`}+${JSON.stringify(trimAssertsDir(fileName))}`
209
241
  };
210
242
  default:
211
243
  return { relative: true };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@marko/vite",
3
3
  "description": "A Marko plugin for Vite",
4
- "version": "2.4.9",
4
+ "version": "3.0.1",
5
5
  "author": "Dylan Piercey <dpiercey@ebay.com>",
6
6
  "bugs": "https://github.com/marko-js/vite/issues",
7
7
  "dependencies": {