sapper icon indicating copy to clipboard operation
sapper copied to clipboard

Make sapper flag --cwd for dev and build work when installation is in sub directory

Open floratmin opened this issue 3 years ago • 3 comments

This pull request solves the problem from https://github.com/sveltejs/sapper/issues/922 probably https://github.com/sveltejs/sapper/issues/1074 and some of the problems of https://github.com/sveltejs/sapper/issues/1575 .

With this commit it is possible to have the sapper installation in a sub directory and the build directory in a directory which can be located somewhere else.

The only thing to adjust in the project is the directory for loading the files from the static directory. For this we change the line to sirv('./$cwd/static', { dev }) in the file server.js in the project created trough the sapper template.

The use of the export_build variable feels a little hacky to me, perhaps somebody finds a more elegant solution for this.

Many tests fail, but this fix works with a clean template and my sample template. My sample template for testing the --cwd option can be found here: https://github.com/floratmin/sapper-subdirectory-example

floratmin avatar Oct 03 '20 07:10 floratmin

I also updated my sample template at https://github.com/floratmin/sapper-subdirectory-example and added scripts with the cwd flag as absolute path. Every combination works. In my nx workspace I also used the additional flags --routes and --static with no problems.

floratmin avatar Oct 04 '20 18:10 floratmin

@benmccann linting is passing now and from 150 tests only one is failing. To make the tests passing I had to made an adjustment in the sapper code. Otherwise I would have to edit 23 test files and change all occurrences of build({ cwd: __dirname }) to build({ cwd: __dirname, root: __dirname }). I thought that also other people could use tests in this way and therefore preferred this approach.

floratmin avatar Oct 14 '20 08:10 floratmin

Thanks. Sorry this got dropped a bit. All our focus has been on SvelteKit. It might be better to make sure anything you want to do is supported there. I'm a bit hesitant to make many changes to Sapper except for bug fixes

benmccann avatar Mar 26 '21 02:03 benmccann

SvelteKit 1.0 is now out and Sapper is deprecated, so I'm going to close this

benmccann avatar Jan 11 '23 16:01 benmccann