Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Webpack 网页包。构建组件库_Webpack - Fatal编程技术网

Webpack 网页包。构建组件库

Webpack 网页包。构建组件库,webpack,Webpack,我想构建我的组件库,例如在MaterialUI中 所有构建都应该动态地遍历目录 有一件事我搞不清楚,那就是分别组装每个按钮、选择等,这样您就可以在dist目录中找到它: dist/Buttons/PrimaryButton/PrimaryButton.js dist/Buttons/PrimaryButton/SecondaryButton.js 我的网页包配置: const path = require("path"); module.exports = { entr

我想构建我的组件库,例如在MaterialUI中

所有构建都应该动态地遍历目录

有一件事我搞不清楚,那就是分别组装每个按钮、选择等,这样您就可以在dist目录中找到它:

dist/Buttons/PrimaryButton/PrimaryButton.js

dist/Buttons/PrimaryButton/SecondaryButton.js

我的网页包配置:

const path = require("path");

module.exports = {
  entry: "./src/components/lib.ts",
  output: {
    filename: "index.js",
    path: path.resolve(__dirname, "dist"),
    library: "",
    libraryTarget: "commonjs"
  },
  module: {
    rules: [
      {
        test: /\.(j|t)sx?$/,
        loader: "babel-loader",
        exclude: /node_modules/
      },
      {
        test: /\.(j|t)s?$/,
        loader: "babel-loader",
        exclude: /node_modules/
      },
      {
        test: /\.s[ac]ss$/i,
        use: ["style-loader", "css-loader", "sass-loader"]
      },
      {
        test: /\.(png|jpg|jpeg|gif|svg|ico)$/,
        exclude: /node_modules/,
        use: [
          {
            loader: "file-loader",
            options: {
              name: "assets/[name].[ext]"
            }
          }
        ]
      },
      {
        test: /\.(woff(2)?|ttf|eot)$/,
        exclude: /node_modules/,
        use: [
          {
            loader: "file-loader",
            options: {
              name: "src/assets/fonts/[name].[ext]"
            }
          }
        ]
      }
    ]
  },
  resolve: {
    extensions: [".js", ".ts", ".tsx"],
    alias: {
      components: path.resolve(__dirname, "src/components"),
      constants: path.resolve(__dirname, "src/constants"),
      assets: path.resolve(__dirname, "src/assets"),
      styleguide: path.resolve(__dirname, "src/styleguide")
    }
  }
};
我的主要按钮:

import React from "react";
import "./style.sass";
import { IButton } from "components/Buttons/Interfaces/IButton";

const PrimaryButton: React.FC<IButton> = ({ children, onClick, ...rest }) => {
  const handleClickButton = () => {
    onClick();
  };
  return (
    <button className="primary-button" onClick={handleClickButton} {...rest}>
      {children}
    </button>
  );
};

export default PrimaryButton;
在google上我发现了类似的东西,但它构建了我的index.js文件,没有按钮,我将其导出到lib.js

您可以查看

  entry: {
    "Buttons/PrimaryButton/PrimaryButton": './src/path/to/primaryButton.js',
    "Buttons/PrimaryButton/SecondaryButton": './src/path/to/secondaryButton.js',
  },
您可以检查及其各种选项:

  entry: {
    "Buttons/PrimaryButton/PrimaryButton": './src/path/to/primaryButton.js',
    "Buttons/PrimaryButton/SecondaryButton": './src/path/to/secondaryButton.js',
  },

不,它应该是动态的。我知道有多个条目:)@Marty我还没有找到另一个内置的解决方案,但我想到了一个主意,你可以创建一个动态条目函数。此函数用于检查每个生成组件文件夹中的可用文件,并返回所需的入口点对象列表。否。它应该是动态的。我知道有多个条目:)@Marty我还没有找到另一个内置的解决方案,但我想到了一个主意,你可以创建一个动态条目函数。此函数用于检查每个构建组件文件夹中的可用文件,并返回所需的入口点对象列表。