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

Custom Source filename #102

Open
crephix opened this issue May 11, 2017 · 2 comments
Open

Custom Source filename #102

crephix opened this issue May 11, 2017 · 2 comments

Comments

@crephix
Copy link

crephix commented May 11, 2017

Hey,
I am using:

		app.use(
			sass({
				src: path.join(__dirname, '/common/sass'),
				dest: path.join(__dirname, '../wwwroot/stylesheets'),
				prefix: '/stylesheets',
			})
		)

but it will only pick up the sass file if I call it "style.scss" instead of "bootstrap.scss" for example. Is there a way to specify the source filename? I'd like to keep it named bootstrap.scss instead of style.scss.

Same question applies to the dest filename, can I give it a custom name which differs from the source css filename?

@am11
Copy link
Collaborator

am11 commented May 11, 2017

Hey @crephix. Thanks for reaching out! 🌮

At the moment, we only replace the .css extension with .scss from requested path to deduce the source filename.

What do you think if we extend the API by delegating this control to the consumer though a user-defined source-file provider function? Something like:

sassMiddlewareOptions = {
  sourceFileProvider: (requestContext) => getSourceFilenameFor ( requestContext.requestedPath );
};

// as an alternative to:

sassMiddlewareOptions = {
  src: path.join(__dirname, '/common/sass'),
  dest: path.join(__dirname, '../wwwroot/stylesheets'),
  prefix: '/stylesheets',
};

where middleware will inject the consumer's initial options and request objects to the requestContext and consumer will return an absolute path to .s[ac]ss file (String).

Additionally, we can also extend this approach to in-memory strings compilation, which node-sass provides OOTB:

sassMiddlewareOptions = {
  sourceProvider: (requestContext) => getSourceFor ( requestContext.requestedPath );
};

here in getSourceFor(..) function, consumer might be reading source content from (for instance) a remote server based on the requested path. With these options, middleware will asyncronously proceed once the source provider function returns the source contents or path to compile.

@crephix
Copy link
Author

crephix commented May 12, 2017

Sounds like a great enhancement for me.

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

No branches or pull requests

2 participants