Git Product home page Git Product logo

sass-alias's Introduction

sass-alias

sass-alias is a node-sass and dart-sass importer that brings aliasing to sass.

Installation

This package can be installed from npm or yarn by running one of the following commands.

Install using npm:

npm install sass-alias

Install using yarn:

yarn add sass-alias

Introduction

sass-alias brings sass the capability to import files using aliasing, this make importing more easy.

Example

Let's imagine we have the following project structure:

project
├───components
│	└───button
│		├───button.module.scss
│		└───button.component.js
│
└───resources
	└───scss
		├───colors.scss
		└───utils.scss

If we want to import colors into button.module.scss the resulting path should look like this

@import '../../resources/scss/colors.scss';

/* more scss stuff... */

If we use sass-alias the resulting path could look like this

@import '@scss/colors.scss';

/* more scss stuff... */

Configuration

using sass node-sass or dart-sass

import path from 'path';
import sass from 'sass';

import { create } from 'sass-alias';

sass.renderSync({
	importer: create({
		'@scss': path.join(__dirname, 'scss'),
	}),
});

using sass-loader in webpack

// webpack.config.js

const { create } = require('sass-alias');

module.exports = {
	module: {
		rules: [
			{
				test: /^.*\.(sass|scss)$/,
				use: [
					{
						loader: 'sass-loader',
						options: {
							sassOptions: {
								importer: create({
									'@scss': path.join(__dirname, 'scss'),
								}),
							},
						},
					},
				],
			},
		],
	},
};

License

This project is licensed under the MIT License, see the LICENSE.md file for details

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.