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
20 changes: 11 additions & 9 deletions src/load-config-meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,30 @@ export const loadConfigMeta = async (cwd?: string) => {
| OutputTargetWithDir
| undefined;

// 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;

if (wwwTarget) {
// Get path from dev-server root to www
// If dir is relative, it's already relative to project root (same as devServer.root)
const wwwDir = wwwTarget.dir!;
const relativePath = isAbsolute(wwwDir) ? relative(devServer.root!, wwwDir) : wwwDir;
const relativePath = isAbsolute(wwwDir) ? relative(rootDir, wwwDir) : wwwDir;

// Use buildDir from config (defaults to 'build' for www target)
const buildDir = (wwwTarget as unknown as { buildDir?: string }).buildDir ?? 'build';
// Stencil may resolve buildDir to absolute path, so we need to handle that
let buildDir = (wwwTarget as unknown as { buildDir?: string }).buildDir ?? 'build';
if (buildDir && isAbsolute(buildDir)) {
buildDir = buildDir === wwwDir ? '' : relative(wwwDir, buildDir);
}

const entryPath = join(relativePath, buildDir, fsNamespace);
stencilEntryPath = entryPath === '' ? '.' : entryPath.startsWith('.') ? entryPath : `./${entryPath}`;
} else if (distTarget || loaderBundleTarget) {
// Fall back to dist or loader-bundle target
const target = distTarget ?? loaderBundleTarget!;

// 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!;

// 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
Expand Down
149 changes: 149 additions & 0 deletions test-projects/explicit-dir/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-projects/explicit-dir/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-projects/explicit-dir/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',
},
],
};
4 changes: 4 additions & 0 deletions test-projects/explicit-dir/test-config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createConfig } from '../../dist/index.js';

const config = await createConfig();
console.log('stencilEntryPath:', process.env.STENCIL_ENTRY_PATH);
149 changes: 149 additions & 0 deletions test-projects/www/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-projects/www/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "test-www",
"private": true,
"type": "module",
"devDependencies": {
"@stencil/core": "^4.0.0"
}
}
9 changes: 9 additions & 0 deletions test-projects/www/stencil.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Config } from '@stencil/core';

export const config: Config = {
namespace: 'TestApp',
devServer: {
port: 3335,
},
outputTargets: [{ type: 'www', serviceWorker: null }],
};
4 changes: 4 additions & 0 deletions test-projects/www/test-config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createConfig } from '../../dist/index.js';

const config = await createConfig();
console.log('stencilEntryPath:', process.env.STENCIL_ENTRY_PATH);
Loading