我有一个带有故事书的复读/描述项目。 故事书发挥了巨大作用,但一旦我开始用别物进口档案,就会坠毁。
例:
import Foo from "@components/foo" => crash
import Foo from "../../components/foo" => ok
服饰品的罚款。 这个问题只与故事书有关。
我的故事:
module.exports = {
stories: ["../**/stories.tsx"],
webpackFinal: (config) => {
return {
...config,
module: {
...config.module,
rules: [
{
test: /.(ts|js)x?$/,
exclude: /node_modules/,
use: { loader: "babel-loader" },
},
{ test: /.css$/, use: ["style-loader", "css-loader"] },
{ test: /.(png|jpg|gif)$/, use: ["file-loader"] },
{
test: /.svg$/,
use: [
{
loader: "babel-loader",
},
{
loader: "react-svg-loader",
options: {
jsx: true,
},
},
],
},
],
},
};
},
typescript: {
check: false,
checkOptions: {},
reactDocgen: "react-docgen-typescript",
reactDocgenTypescriptOptions: {
shouldExtractLiteralValuesFromEnum: true,
propFilter: (prop) =>
prop.parent ? !/node_modules/.test(prop.parent.fileName) : true,
},
},
};
我的系列会议:
/* eslint-env node */
const path = require("path");
const TerserPlugin = require("terser-webpack-plugin");
const Dotenv = require("dotenv-webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const isProductionMode = (mode) => mode === "production";
module.exports = () => {
const env = require("dotenv").config({ path: __dirname + "/.env" });
const nodeEnv = env.parsed.NODE_ENV;
return {
mode: "development",
entry: "./src/index.tsx",
output: {
path: path.join(__dirname, "./dist"),
filename: "[name].[contenthash].bundle.js",
publicPath: "/",
},
resolve: {
extensions: [".ts", ".tsx", ".js", "jsx", ".json"],
alias: {
"@api": path.resolve(__dirname, "src/api/"),
"@assets": path.resolve(__dirname, "src/assets/"),
"@components": path.resolve(__dirname, "src/components/"),
"@containers": path.resolve(__dirname, "src/containers/"),
"@data": path.resolve(__dirname, "src/data/"),
"@i18n": path.resolve(__dirname, "src/i18n/"),
"@models": path.resolve(__dirname, "src/models/"),
"@pages": path.resolve(__dirname, "src/pages/"),
"@src": path.resolve(__dirname, "src/"),
"@stores": path.resolve(__dirname, "src/stores/"),
"@utils": path.resolve(__dirname, "src/utils/"),
},
},
module: {
rules: [
{
test: /.(ts|js)x?$/,
exclude: /node_modules/,
use: { loader: "babel-loader" },
},
{ test: /.css$/, use: ["style-loader", "css-loader"] },
{ test: /.(png|jpg|jpeg|gif)$/, use: ["file-loader"] },
{
test: /.svg$/,
use: [
{
loader: "babel-loader",
},
{
loader: "react-svg-loader",
options: {
jsx: true,
},
},
],
},
],
},
devServer: {
historyApiFallback: true,
port: 3000,
inline: true,
hot: true,
},
plugins: [
new HtmlWebpackPlugin({
template: "./src/index.html",
}),
new Dotenv(),
],
optimization: {
minimize: isProductionMode(nodeEnv),
minimizer: isProductionMode(nodeEnv) ? [new TerserPlugin()] : [],
splitChunks: { chunks: "all" },
},
};
};
如何解决这一问题? 我在网上读到第5.24.2和6.1.20号故事书,因此它们是最新版本。