Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack (with sass-loader) - scss file @import does not recognize resolve alias

My project structure:

webpack.config.js app--     --> src    ---->> components    ------>>> myComponent.js    ------>>> myComponent.scss     --> styles    ---->> variables.scss 

In webpack.config module.exports:

... resolve: {     alias: {        styles: path.join(__dirname, 'app/styles')     } } 

In my file - myComponent.scss:

@import "styles/variables"; 

I am getting this error when building bundle.js:

Module build failed: @import "styles/variables"; ^       File to import not found or unreadable: styles/variables 

How can I @import aliases in sass files?

like image 420
tome Avatar asked Jan 11 '16 08:01

tome


1 Answers

I was able to use, on a stylesheet, an alias that I defined in webpack by using the following:

@import '~alias/variables'; 

just by prefixing the alias with ~ did the trick for me, as suggested by documentation in here

like image 143
BenR Avatar answered Sep 26 '22 15:09

BenR