Skip to content

lucagoslar/svelte-preprocess-sass-alias-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

svelte-preprocess-sass-alias-import

๐Ÿ—ƒ Import external stylesheets with the help of absolute paths.

Though this package might also work in a different environment that uses sass, it should be noted that it serves the legacy importer used by svelte-preprocess.

build and test

Setup

  1. Import SassAlias from svelte-preprocess-sass-alias-import.
import { SassAlias } from 'svelte-preprocess-sass-alias-import';
  1. Instantiate SassAlias and pass it an object containing your rules.
const alias = new SassAlias({
	$var: 'src/scss',
  @var: ["src", "scss"]
});
  1. Add and bind the SassAlias instance to the project's preprocessor. (Sample usage with SvelteKit.)
// svelte.config.js
import preprocess from 'svelte-preprocess';

/** @type {import('@sveltejs/kit').Config} */
const config = {
	preprocess: [
		preprocess({
			sass: {
				importer: [alias.resolve.bind(alias)],
			},
			scss: {
				importer: [alias.resolve.bind(alias)],
			}, // Use for both sass and or scss
		}),
	],
};

export default config;
// vite.config.ts
// Only required if you want to import stylesheets into an already imported stylesheet

const config: UserConfig = {
	css: {
		preprocessorOptions: {
			sass: {
				importer: [alias.resolve.bind(alias)],
			},
			scss: {
				importer: [alias.resolve.bind(alias)],
			},
		},
	},
};
  1. Import files using your predefined aliases.
<!-- *.svelte -->
<style lang="scss">
  @import "$var/main.scss";
</style>
<!-- *.svelte -->
<style lang="sass">
  @use "@var/main.scss"
</style>
// *.scss
@use '@var/main.scss';

Contribute

Install all (dev-)dependencies by running the following.

  npm i

Make sure husky is being installed too.

  npm run prepare


And off we go โ€ฆ

Build this project with the following.

npm run build

Contributions of any kind are very much appreciated.

About

๐Ÿ—ƒ Import external stylesheets with the help of absolute paths.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published