I'm using sass-loader to load my scss files inside my project and also using the node_modules resolver eg: @import '~styleguide/src/vars.scss'
When i'm trying to load react-storybook i'm passing this to webpack.config.js
const path = require('path');
const autoprefixer = require('autoprefixer');
// load the default config generator.
var genDefaultConfig = require('@kadira/storybook/dist/server/config/defaults/webpack.config.js');
module.exports = function(config, env) {
var config = genDefaultConfig(config, env);
config.module.loaders.push({
test: /\.html$/, loader: 'raw'
});
config.module.loaders.push({
test: /\.scss$/,
loaders: ['style', 'css?sourceMap', 'postcss-loader', 'sass?config=sassLoader']
});
config.sassLoader = {
includePaths: [
path.resolve(__dirname, '..', 'src/scss')
],
sourceMap: true
}
config.postcss = function() {
return [autoprefixer];
}
return config;
};
From what i can read from sass-loader
the node_module resolve should be automatic but it appears is not working:
here's the error message
ERROR in ./~/css-loader?sourceMap!./~/postcss-loader!./~/sass-loader?config=sassLoader!./src/component.scss
Module build failed:
@import '~styleguide/src/vars';
^
File to import not found or unreadable: ~styleguide/src/vars
Parent style sheet: stdin
Anyone has an idea why this is happening?
This is working for us:
/* eslint-env node */
const path = require('path');
const include = path.resolve(__dirname, '..', 'src');
module.exports = {
module: {
rules: [
{
test: /\.scss$/,
loaders: ["style-loader", "css-loader", "sass-loader"],
include
}
]
}
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.