I am trying to enable source maps using Angular and Storybook. I have consulted with the Storybook documentation on updating the webpack config to no avail. When adding a new rule failed, I tried updating the rule that was already in the default webpack config in .storybook/main.js
with the following:
//...
webpackFinal: async (config, {configType}) => {
if(configType === 'DEVELOPMENT') {
config.devtool = 'source-map';
config.module.rules[1].test = /\.scss$/;
config.module.rules[1].use[1].options.sourceMap = true;
config.module.rules[1].use[2].options.sourceMap = true;
}
return config;
}
And when I log the config, I see my changes are in the final config, but I am still not getting source maps as expected:
Below is what I get from the final config after my changes. What's also weird is how the test
field doesn't seem to be changing:
{
"exclude": [],
"test": {},
"use": [
{
"loader": "/Users/mike.v.m/workspace/ng-farmers/node_modules/raw-loader/dist/cjs.js"
},
{
"loader": "/Users/mike.v.m/workspace/ng-farmers/node_modules/postcss-loader/src/index.js",
"options": { "ident": "embedded", "sourceMap": false }
},
{
"loader": "/Users/mike.v.m/workspace/ng-farmers/node_modules/sass-loader/dist/cjs.js",
"options": {
"implementation": {
"info": "node-sass\t4.14.1\t(Wrapper)\t[JavaScript]\nlibsass \t3.5.5\t(Sass Compiler)\t[C/C++]",
"types": {},
"TRUE": {},
"FALSE": {},
"NULL": {}
},
"sourceMap": false,
"sassOptions": {
"precision": 8,
"includePaths": [],
"outputStyle": "expanded"
}
}
}
for less i came to this solution
webpackFinal: (config, { configType }) => {
// https://storybook.js.org/docs/react/configure/webpack
// `configType` has a value of 'DEVELOPMENT' or 'PRODUCTION'
const include = path.resolve(__dirname, '../');
const ruleChanger = (rule) => {
delete rule.rules;
rule.include = include;
}
config.module.rules.forEach(rule => {
const pattern = rule.test.toString();
if(pattern === '/\\.(?:less)$/i') {
ruleChanger(rule)
rule.use = ['style-loader', 'css-loader', 'less-loader'];
} else if(pattern === '/\\.(?:css)$/i') {
ruleChanger(rule)
rule.use = ['style-loader', 'css-loader'];
}
})
return config;
},
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.