这是我的.storybook文件夹中的webpack.config.js
const path = require('path');
const TSDocgenPlugin = require('react-docgen-typescript-webpack-plugin');
module.exports = (baseConfig, env, defaultConfig) => {
defaultConfig.module.rules.push({
test: /\.(ts|tsx)$/,
loader: require.resolve('awesome-typescript-loader')
});
defaultConfig.plugins.push(new TSDocgenPlugin());
defaultConfig.resolve.extensions.push('.ts', '.tsx');
return defaultConfig;
};
这是我的tsconfig.json
配置文件
{
"compilerOptions": {
"outDir": "build/lib",
"module": "commonjs",
"target": "es5",
"lib": ["es5", "es6", "es7", "es2017", "dom"],
"sourceMap": true,
"allowJs": false,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"baseUrl": "src",
"types": ["node"]
"forceConsistentCasingInFileNames": true,
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"suppressImplicitAnyIndexErrors": true,
"noUnusedLocals": true,
"declaration": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true
"typeRoots": [
"node_modules/@types"
]
},
"include": ["src/**/*", "types/**/*"],
"exclude": ["node_modules", "build", "scripts"]
}
当我尝试在我的任何react组件中导入任何scss
文件时,我都找不到模块错误。
import style from './Button.scss'
请指导我一个如何配置webpack.config.js
以在我的 tsx 文件中支持 scss import
答案 0 :(得分:0)
从来没有使用TypeScript,但是我想您必须将类似的内容推送到您的规则中:
{
test: /\.scss$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }, { loader: 'sass-loader' }],
},
因此您的webpack.config.js
如下所示:
const path = require('path');
const TSDocgenPlugin = require('react-docgen-typescript-webpack-plugin');
module.exports = (baseConfig, env, defaultConfig) => {
defaultConfig.module.rules.push({
test: /\.(ts|tsx)$/,
loader: require.resolve('awesome-typescript-loader')
});
defaultConfig.module.rules.push({
test: /\.scss$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }, { loader: 'sass-loader' }],
});
defaultConfig.plugins.push(new TSDocgenPlugin());
defaultConfig.resolve.extensions.push('.ts', '.tsx');
return defaultConfig;
};
请不要忘记将加载程序添加到您的package.json