@siemens/live-preview 49.14.0 → 49.16.0
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/esbuild-component-loader.mjs +12 -8
- package/package.json +1 -1
|
@@ -10,6 +10,7 @@ const livePreviewComponentLoader = {
|
|
|
10
10
|
const root = url.searchParams.get('root');
|
|
11
11
|
const examples = url.searchParams.get('examples');
|
|
12
12
|
const webcomponents = url.searchParams.get('webcomponents');
|
|
13
|
+
const rel = url.searchParams.get('rel');
|
|
13
14
|
|
|
14
15
|
if (!root) {
|
|
15
16
|
throw 'config error: need to pass "root" (path)';
|
|
@@ -18,7 +19,7 @@ const livePreviewComponentLoader = {
|
|
|
18
19
|
return {
|
|
19
20
|
namespace: 'live-preview-component-loader',
|
|
20
21
|
path: args.path,
|
|
21
|
-
pluginData: { root, webcomponents, examples }
|
|
22
|
+
pluginData: { root, webcomponents: webcomponents === 'true', examples, rel: rel === 'true' }
|
|
22
23
|
};
|
|
23
24
|
});
|
|
24
25
|
|
|
@@ -27,19 +28,22 @@ const livePreviewComponentLoader = {
|
|
|
27
28
|
filter: /(@siemens|@simpl)\/live-preview\/component-loader.*/,
|
|
28
29
|
namespace: 'live-preview-component-loader'
|
|
29
30
|
},
|
|
30
|
-
async ({ pluginData: { root, webcomponents, examples } }) => {
|
|
31
|
+
async ({ pluginData: { root, webcomponents, examples, rel } }) => {
|
|
31
32
|
const watchDirs = [root];
|
|
32
33
|
|
|
33
34
|
let code = 'export default { load: function (path) { switch (path) {';
|
|
34
35
|
const files = [];
|
|
35
36
|
const webcomponentsFiles = [];
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)) {
|
|
37
|
+
const glob = path.posix.join(root, examples.replace(/\.ts$/, '.{ts,tsx,vue,js}'));
|
|
38
|
+
const rootNormalized = path.normalize(root);
|
|
39
|
+
// posix: true needed for windows
|
|
40
|
+
for await (const file of globIterate(glob, { posix: true })) {
|
|
40
41
|
if (file.endsWith('.ts')) {
|
|
41
|
-
const fileName = file
|
|
42
|
-
|
|
42
|
+
const fileName = file
|
|
43
|
+
.replace(new RegExp('^' + rootNormalized + '/'), '')
|
|
44
|
+
.replace(/\.ts$/, '');
|
|
45
|
+
let importFileName = rel ? `./${fileName}` : file.replace(/\.ts$/, '');
|
|
46
|
+
code += `case '${fileName}': return import('${importFileName}');`;
|
|
43
47
|
files.push(fileName);
|
|
44
48
|
} else {
|
|
45
49
|
webcomponentsFiles.push(file.replace(root + '/', '').replace(/\.(tsx|vue|js)$/, ''));
|