Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions src/load-config-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { loadConfig, OutputTargetWww } from '@stencil/core/compiler';
import { findUp } from 'find-up';
import { existsSync } from 'fs';
import { isAbsolute, join, relative } from 'path';
import { dirname, isAbsolute, join, relative } from 'path';

/**
* Common shape for output targets with dir and buildDir properties.
Expand Down Expand Up @@ -69,11 +69,23 @@ export const loadConfigMeta = async (cwd?: string) => {
// Get path from dev-server root to target dir
// If dir is relative, it's already relative to project root (same as devServer.root)
const targetDir = target.dir!;
const relativePath = isAbsolute(targetDir) ? relative(devServer.root!, targetDir) : targetDir;

// Use stencil config directory as fallback if devServer.root is not usable
const configDir = dirname(stencilConfigPath);
const rootDir = devServer.root && devServer.root !== '/' ? devServer.root : configDir;

const relativePath = isAbsolute(targetDir) ? relative(rootDir, targetDir) : targetDir;

// dist/loader-bundle use empty string as default buildDir
// Stencil may resolve buildDir to absolute path, so we need to handle that
let buildDir = target.buildDir ?? '';
if (buildDir && isAbsolute(buildDir)) {
// If buildDir is absolute, compute relative path from targetDir
// If buildDir equals targetDir, use empty string (no subdirectory)
buildDir = buildDir === targetDir ? '' : relative(targetDir, buildDir);
}

// Path structure: dir/buildDir/namespace/namespace (extra namespace folder)
const buildDir = target.buildDir ?? '';
const entryPath = join(relativePath, buildDir, fsNamespace, fsNamespace);
stencilEntryPath = entryPath === '' ? '.' : entryPath.startsWith('.') ? entryPath : `./${entryPath}`;
} else {
Expand Down
149 changes: 149 additions & 0 deletions test-project/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions test-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test-stencil-project",
"private": true,
"type": "module",
"devDependencies": {
"@stencil/core": "^4.0.0"
}
}
11 changes: 11 additions & 0 deletions test-project/stencil.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Config } from '@stencil/core';

export const config: Config = {
namespace: 'TestAssetsGlobalStyle',
outputTargets: [
{
type: 'dist',
dir: 'dist/loader-bundle',
},
],
};
9 changes: 9 additions & 0 deletions test-project/test-config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { createConfig } from '../dist/index.js';

try {
const config = await createConfig();
console.log('stencilEntryPath:', process.env.STENCIL_ENTRY_PATH);
console.log('Config created successfully');
} catch (e) {
console.error('Error:', e.message);
}
Loading