我正在使用sass-loader在我的项目中加载我的scss文件,并使用node_modules解析器,例如:@import '~styleguide/src/vars.scss'
当我正在尝试加载react-storybook时,我将其传递给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;
};
从我可以从sass-loader
读取的内容,node_module解析应该是自动的,但看起来不起作用:
这是错误消息
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
任何人都知道为什么会这样?
答案 0 :(得分:0)
这对我们有用:
/* 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
}
]
}
};