Skip to content

Include file from outside of the project root #634

@ghost

Description

According to the docs:

If your build contains multiple entry points in separate directories, the directory structure will be replicated into the output directory starting from the lowest common ancestor directory among all input entry point paths. For example, if there are two entry points src/home/index.ts and src/about/index.ts, the output directory will contain home/index.js and about/index.js. If you want to customize this behavior, you chould change the outbase directory.

Full context: I'm refactoring svelte-typewriter codebase, it's essentially composed by the library source code on the root directory, and a example subdirectory with a demo Svelte project for testing purposes with the following directory structure:

.
├── build.js
├── jsconfig.json
├── package.json
├── public
│   ├── favicon.ico
│   └── index.html
├── rollup.config.js
├── src
│   ├── App.svelte
│   ├── components
│   │   ├── TypewriterControls.svelte
│   │   └── TypewriterMode.svelte
│   ├── index.js
│   └── pages
│       ├── Cascade.svelte
│       ├── Default.svelte
│       ├── Loop.svelte
│       └── LoopRandom.svelte
└── yarn.lock

I'm building the Svelte component with the following config:

await esbuild.build({
	entryPoints: ['./src/index.js'],
	platform: 'browser',
	bundle: true,
	format: 'esm',
	splitting: true,
	outbase: './',
	outdir: 'public/build',
	plugins: [sveltePlugin()]
})

When i try to import ./src/Typewriter.svelte from ./example/src/components/TypewriterControls.svelte, esbuild end up including unnecessary files/folders from root directory (like example, and src), is there any viable way to import a file from outside of the project folder, and build it with outdir without replicating the whole directory structure of the imported file parent directory?


Edit: i even tried including outbase in the config as pointed in the docs, but with no luck, i received the following error:

Cannot traverse from directory "../src/helpers" to chunk "chunk.34VXZT2I.js"

I'm not 100% sure of what could be happening here, but i suspect that it might have something to do with the *.js files imported by the Svelte component not being able to properly import their modules

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions