0

有一个我无法摆脱的问题。我正在尝试制作自己的 npm 包,而且我已经很接近了。我在我的 npm 包中添加了各种 npm 包,例如 B. Bootstrap。并且 dist 文件夹不受管理。这就是为什么我的包裹不起作用。我应该怎么办?[1]:https ://i.stack.imgur.com/ZOFAp.png

rollup.config.js 是:

[import { babel } from "@rollup/plugin-babel";
import resolve from "@rollup/plugin-node-resolve";
import external from "rollup-plugin-peer-deps-external";
import { terser } from "rollup-plugin-terser";
import postcss from "rollup-plugin-postcss";
import commonjs from "@rollup/plugin-commonjs";
import nodePolyfills from "rollup-plugin-polyfill-node";
import replace from "@rollup/plugin-replace";

export default [
  {
    input: "./src/index.js",
    output: [
      {
        file: "dist/index.js",
        format: "cjs",
      },
      {
        file: "dist/index.es.js",
        format: "es",
        exports: "named",
      },
    ],

    plugins: [
      replace({
        preventAssignment: true,
        "process.browser": true,
        "process.env.NODE_ENV": JSON.stringify("development"),
      }),
      postcss({
        plugins: [],
        minimize: true,
      }),
      babel({
        exclude: "node_modules/**",
        presets: ["@babel/preset-react"],
      }),
      commonjs({
        include: " /node_modules/",
        namedExports: {
          react: ["useState", "useEffect"],
          bootstrap: ["Modal", "Button"],
          formik: ["useFormik"],
        },
      }),
      nodePolyfills(),
      external(),
      resolve(),
      terser(),
    ],
  },
];
]

和我的 package.json

{
  "name": "funnyform",
  "version": "1.4.0",
  "description": "A simple react component for Form with Formik and Modal",
  "main": "dist/index.js",
  "module": "dist/index.es.js",
  "prebuild": "npm install",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "storybook": "start-storybook -p 6006",
    "build-storybook": "build-storybook",
    "build-lib": "rollup -c"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/core": "^7.15.5",
    "@babel/preset-react": "^7.14.5",
    "@rollup/plugin-babel": "^5.3.0",
    "@rollup/plugin-commonjs": "^20.0.0",
    "@rollup/plugin-node-resolve": "^13.0.5",
    "@rollup/plugin-replace": "^3.0.0",
    "@storybook/addon-actions": "^6.3.8",
    "@storybook/addon-essentials": "^6.3.8",
    "@storybook/addon-links": "^6.3.8",
    "@storybook/react": "^6.3.8",
    "babel-loader": "^8.2.2",
    "bootstrap": "^4.6.0",
    "formik": "^2.2.9",
    "node-sass": "^6.0.1",
    "react": "^17.0.2",
    "react-bootstrap": "^1.6.4",
    "react-dom": "^17.0.2",
    "rollup": "^2.58.0",
    "rollup-plugin-babel": "^4.4.0",
    "rollup-plugin-peer-deps-external": "^2.2.4",
    "rollup-plugin-polyfill-node": "^0.7.0",
    "rollup-plugin-postcss": "^4.0.1",
    "rollup-plugin-terser": "^7.0.2"
  },
  "peerDependencies": {
    "react": "^17.0.2"
  },
  "dependencies": {
    "bootstrap": "^4.6.0",
    "formik": "^2.2.9",
    "node-sass": "^6.0.1",
    "react-bootstrap": "^1.6.4"
  }
}

非常感谢

4

0 回答 0