svelte-preprocess-sass-alias-import
TypeScript icon, indicating that this package has built-in type declarations

1.0.0Β β€’Β PublicΒ β€’Β Published

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.

Package Sidebar

Install

npm i svelte-preprocess-sass-alias-import

Weekly Downloads

115

Version

1.0.0

License

MIT

Unpacked Size

11.2 kB

Total Files

9

Last publish

Collaborators

  • lucagoslar