当它是另一个项目的依赖项时,捆绑我的汇总项目是什么

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了当它是另一个项目的依赖项时,捆绑我的汇总项目是什么相关的知识,希望对你有一定的参考价值。

我正在尝试使用2个项目创建一个React网站:

  • 用于存储组件清单的反应套件
  • 运行React服务器(并具有React-kit作为依赖项的React-app)

[我主要跟随this tutorial使用Rollup(和babel)构建我的React-kit。

我使用私有的github仓库将React-Kit作为依赖项放到我的React-App中:(如果需要,我在问题的末尾添加了我所有的构建文件(两个项目的汇总,babel和webpack)。)

package.json


  /* ... */
  "dependencies": 
    "react-kit": "github:myUser/react-Kit",  
    /* ... */
  

首先在本地运行良好,这对我来说是个大问题?是谁干的?

研究期间,我注意到:

  • dist/在React-Kit github存储库中(但src/在这里)不是
  • dist/存在于我的本地React-App/node_modules/react-kit/上(只有package*.json不是 src/
  • [当我在React-App上执行npm i时,将下载React-kit(我理解^^的那部分,然后由他的汇总配置文件捆绑在一起。

我的反应包如何捆绑在一起?当我在React-App上执行npm i时,谁调用了启动汇总?

Second我打算使用Jenkins在生产中部署React-App项目,但是在这种情况下我的react-kit / dist不在这里,React-App/node_modules/react-kit仅具有package*.json(所以我的react-app构建失败,因为无法导入react-kit)。

这里发生了什么?我尝试在本地和AWS上同时使用env(dev和prod),但是总是一样。

我想我在这里想念什么。


反应包

rollup.config.js

import babel from 'rollup-plugin-babel'
import commonjs from 'rollup-plugin-commonjs'
import external from 'rollup-plugin-peer-deps-external'
import postcss from 'rollup-plugin-postcss'
import resolve from 'rollup-plugin-node-resolve'
import url from 'rollup-plugin-url'
import svgr from '@svgr/rollup'
import  terser  from 'rollup-plugin-terser'

import pkg from './package.json'

export default 
  input: 'src/lib/index.js',
  output: [
    
      file: pkg.main,
      format: 'cjs',
      sourcemap: true,
    ,
    
      file: pkg.module,
      format: 'es',
      sourcemap: true,
    ,
  ],
  plugins: [
    external(
      // includeDependencies: true,
    ),
    postcss(
      plugins: [],
      minimize: true,
      sourceMap: 'inline',
    ),
    url(),
    svgr(),
    resolve(),
    babel(
      plugins: [
        '@babel/plugin-proposal-object-rest-spread',
        '@babel/plugin-proposal-optional-chaining',
        '@babel/plugin-syntax-dynamic-import',
        '@babel/plugin-proposal-class-properties',
        'transform-react-remove-prop-types',
      ],
      exclude: 'node_modules/**',
    ),
    commonjs(),
    // terser(),    // Activate to minimify
  ],

。babelrc


  "presets": [
    [
      "@babel/preset-env",
      
        "modules": false
      
    ],
    "@babel/preset-react"
  ],
  "env": 
    "test": 
      "presets": [
        [
          "react-app"
        ]
      ]
    
  ,
  "plugins": [
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/plugin-proposal-optional-chaining",
    "@babel/plugin-syntax-dynamic-import",
    "@babel/plugin-proposal-class-properties"
  ]

package.json


  "name": "react-kit",
  "version": "0.1.0",
  "description": "React components dictionary for Projects",
  "author": "",
  "license": "ISC",
  "main": "dist/index.js",
  "module": "dist/index.es.js",
  "jsnext:main": "dist/index.es.js",
  "engines": 
    "node": ">=8",
    "npm": ">=5"
  ,
  "scripts": 
    "dev": "run-p build:watch start",
    "start": "styleguidist server --open",
    "styleguide:build": "styleguidist build",
    "build": "rollup -c",
    "build:watch": "rollup -c -w",
    "test": "jest",
    "test:coverage": "jest --coverage --forceExit --colors",
    "lint": "esw --ext .jsx --ext .js --color",
    "lint:fix": "npm run lint --fix",
    "prepare": "npm run build",
    "prerelease": "npm run lint:fix && npm run test:coverage && npm run build",
    "release": "npm publish",
    "predeploy": "npm run styleguide:build",
    "deploy": "gh-pages -d styleguide"
  ,
  "dependencies": 
    "formik": "^1.5.8"
  ,
  "peerDependencies": 
    "react": "^16.8.6",
    "react-dom": "^16.8.6",
    "react-router-dom": "^5.0.1"
  ,
  "devDependencies": 
    "@babel/core": "^7.5.4",
    "@babel/plugin-proposal-class-properties": "^7.5.0",
    "@babel/plugin-proposal-object-rest-spread": "^7.5.4",
    "@babel/plugin-proposal-optional-chaining": "^7.2.0",
    "@babel/plugin-syntax-dynamic-import": "^7.2.0",
    "@babel/preset-env": "^7.5.4",
    "@babel/preset-react": "^7.0.0",
    "@svgr/rollup": "^4.3.1",
    "babel-core": "^7.0.0-bridge.0",
    "babel-eslint": "^10.0.2",
    "babel-jest": "^24.8.0",
    "babel-plugin-transform-react-remove-prop-types": "^0.4.24",
    "babel-preset-react-app": "^9.0.0",
    "cross-env": "^5.2.0",
    "enzyme": "^3.10.0",
    "enzyme-adapter-react-16": "^1.14.0",
    "eslint": "^6.0.1",
    "eslint-config-airbnb": "^17.1.1",
    "eslint-plugin-flowtype": "^3.11.1",
    "eslint-plugin-import": "^2.18.0",
    "eslint-plugin-jest": "^22.7.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-react": "^7.14.2",
    "eslint-plugin-react-hooks": "^1.6.1",
    "eslint-watch": "^5.1.2",
    "gh-pages": "^2.0.1",
    "jasmine-expect": "^4.0.2",
    "jest": "^24.8.0",
    "jest-pnp-resolver": "^1.2.1",
    "jest-resolve": "^24.8.0",
    "node-sass": "^4.12.0",
    "npm-run-all": "^4.1.5",
    "prop-types": "^15.7.2",
    "react": "^16.8.6",
    "react-app-polyfill": "^1.0.1",
    "react-dom": "^16.8.6",
    "react-router-dom": "^5.0.1",
    "react-styleguidist": "^9.1.11",
    "react-test-renderer": "^16.8.6",
    "rollup": "^1.16.7",
    "rollup-plugin-babel": "^4.3.3",
    "rollup-plugin-commonjs": "^10.0.1",
    "rollup-plugin-node-resolve": "^5.2.0",
    "rollup-plugin-peer-deps-external": "^2.2.0",
    "rollup-plugin-postcss": "^2.0.3",
    "rollup-plugin-terser": "^5.1.1",
    "rollup-plugin-url": "^2.2.2",
    "webpack": "^4.35.3",
    "webpack-blocks": "^2.0.1"
  ,
  "files": [
    "dist"
  ],
  "jest": 
    "collectCoverageFrom": [
      "src/**/*.js,jsx,ts,tsx",
      "!src/**/*.d.ts",
      "!src/**/index.js"
    ],
    "resolver": "jest-pnp-resolver",
    "setupFiles": [
      "react-app-polyfill/jsdom",
      "<rootDir>/scripts/enzymeConfig.js"
    ],
    "testMatch": [
      "**/__tests__/**/*.[jt]s?(x)",
      "**/?(*.)+(spec|test).[jt]s?(x)"
    ],
    "testEnvironment": "jsdom",
    "testURL": "http://localhost",
    "transform": 
      "^.+\\.(js|jsx|ts|tsx)$": "<rootDir>/node_modules/babel-jest",
      "^.+\\.css$": "<rootDir>/scripts/cssTransform.js",
      "^(?!.*\\.(js|jsx|ts|tsx|css|json)$)": "<rootDir>/scripts/fileTransform.js"
    ,
    "transformIgnorePatterns": [
      "[/\\\\]node_modules[/\\\\].+\\.(js|jsx|ts|tsx)$",
      "^.+\\.module\\.(css|sass|scss)$"
    ],
    "moduleDirectories": [
      "node_modules",
      "src"
    ],
    "moduleNameMapper": 
      "^react-native$": "react-native-web",
      "^.+\\.module\\.(css|sass|scss)$": "identity-obj-proxy"
    ,
    "moduleFileExtensions": [
      "web.js",
      "js",
      "web.ts",
      "ts",
      "web.tsx",
      "tsx",
      "json",
      "web.jsx",
      "jsx",
      "node"
    ]
  

React-App

webpack.config.js

const webpack = require('webpack');
const path = require('path');
const Dotenv = require('dotenv-webpack');

const env = process.env.NODE_ENV || 'development';

const config = 
  entry: './src/index.js',
  output: 
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  ,
  plugins: [
    new Dotenv(
      path: `.env.$env !== 'development' ? env : ''`,
    )
  ],
  module: 
    rules: [
      
        test: /\.m?js$/,
        exclude: /(node_modules|bower_components)/,
        use: 
          loader: 'babel-loader',
          options: 
            presets: ['@babel/preset-env']
          
        
      ,
      
        test: /\.css$/,
        use: [
          'style-loader',
          'css-loader'
        ]
      ,
      
        test: /\.less$/,
        use: [
          'style-loader',
          'css-loader',
          'less-loader'
        ]
      
    ]
  ,
  resolve: 
    extensions: [
      '.js',
      '.jsx'
    ]
  


module.exports = config;

babel.config.js

module.exports = function (api) 
  api.cache(true);
  return 
    "presets": [
      "@babel/preset-env",
      "@babel/preset-react"
    ],
    "plugins": [
      "@babel/plugin-proposal-class-properties"
    ]
  
;

。babelrc


  "presets": [
    [
      "@babel/preset-env",
      
        "modules": false
      ,
      "@babel/preset-react'"
    ],
  ],
  "plugins": [
    ["@babel/transform-runtime"]
  ]

答案

NPM documentation,我了解到prepare是用npm install调用的,而在本地环境中没有参数。

您的prepare脚本调用build脚本,然后build脚本调用rollup命令

以上是关于当它是另一个项目的依赖项时,捆绑我的汇总项目是什么的主要内容,如果未能解决你的问题,请参考以下文章

使用纱线工作区将 ui 库与汇总捆绑时导入未定义

尝试安装项目依赖项时运行 npm i(退出代码 1)时发生错误

使用 kotlin + quarkus 注入一些依赖项时出错

添加依赖项时如何自动更新主解决方案?

在 gradle 项目中添加 graphql 依赖项时出错

当它是大写字母时分隔对象字符串c# [重复]