Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default folder #24

Closed
alkorlos opened this issue Aug 11, 2023 · 9 comments
Closed

Change default folder #24

alkorlos opened this issue Aug 11, 2023 · 9 comments

Comments

@alkorlos
Copy link

Hello!

In default vituum routes from src/pages. To change it need to use build.rollupOptions.input.
For example if want change folder and add multi-page support need code:

rollupOptions: {
	input: ['./src/templates/pages/*.html']
}

But there are several problems with this configuration.

If use this config npm run build put files to dist\templates\pages, need dist
Try use build.rollupOptions.output, but it doesn't work for html, full config:

import vituum from 'vituum'

export default {
	build: {
		emptyOutDir: true,
		rollupOptions: {
			input: ['./src/templates/pages/*.html'],
			output: {
				assetFileNames: ({name}) => {
					if (/\.html$/.test(name ?? '')) {
						return '[name]-[extname]';
					}

					if (/\.css$/.test(name ?? '')) {
						return 'css/[name]-[hash][extname]';
					}

					return 'assets/[name]-[hash][extname]';
				},
			},
		},
	},
	plugins: [vituum()]
}

After build css files in dist\css folder, html still in dist\templates\pages.

In issue How to change the path of pug pages when building a project? #5 written "you should use vituum build", but it gives me a error "vituum: command not found"

With npm run dev also a problem.
Page http://localhost:5173/ is empty "localhost page not found". index.html have a different link?
Page http://localhost:5173/templates/pages is empty to as well as several other options that I tried.

For determines where pages routing need to use root?

plugins: [vituum({
    root: './src/templates/pages'
})]

This does not help.

@lubomirblazekcz
Copy link
Member

When you change pages dir, you need to also change it in the config here https://vituum.dev/plugins/pages.html#dir otherwise it will not work

@alkorlos
Copy link
Author

Please tell how exactly need to change dir in this case?
With this code

plugins: [vituum({
  dir: './src/templates/pages'
})]

Same result for npm run build and npm run dev

@lubomirblazekcz
Copy link
Member

It's actually

plugins: [vituum({
  pages: {
    dir: './src/templates/pages'
 }
})]

@alkorlos
Copy link
Author

Thank you!

In the documentation in Get started, there are words "basic multi-page .html support in src/pages". Do you mind if I send pull request some example code next how changing pages dir? I think it will be useful.
Now in documentation no example with rollupOptions and pages dir in one place.

@alkorlos
Copy link
Author

alkorlos commented Aug 11, 2023

Plagin imports give me some bugs, I dont need this plugin, but if
replace

import vituum from 'vituum';

plugins: [vituum({
  pages: {
	  dir: './src/templates/pages'
  }
})],

to

import pages from 'vituum/plugins/pages.js';

plugins: [pages({
 dir: './src/templates/pages'
})]

npm run build give error
"Could not resolve entry module "./src/templates/pages/*.html".
..."

npm run dev give error
"(!) Could not auto-determine entry point from rollupOptions or html files and there are no explicit optimizeDeps.include patterns. Skipping dependency pre-bundling."

The documentation says that plugins can be used separately, is that right?

@lubomirblazekcz
Copy link
Member

lubomirblazekcz commented Aug 11, 2023

That's correct, but vite and pages plugin itself doesn't support globs inside rollupOptions.input, that's something vituum itself (https://github.com/vituum/vituum/blob/main/src/index.js#L26) does automatically via fast-glob. You can do that like this

import fg from 'fast-glob'
import { resolve } from 'path'


rollupOptions: {
	input: fg.sync(['./src/templates/pages/*.html']).map(entry => resolve(process.cwd(), entry))
}

@alkorlos
Copy link
Author

An important point if someone will read this

If redefine vite root, example

root: 'src',

this will not affect in

input: fg.sync(['./src/templates/pages/*.html']).map(entry => resolve(process.cwd(), entry))

need full path with src. @lubomirblazekcz correct?

Now this better way to off Imports plugin?

@lubomirblazekcz
Copy link
Member

I might add imports: false as a config options in future release to make it easier

@alkorlos
Copy link
Author

That would be great thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants