栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

一个项目包含多个package.json文件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

一个项目包含多个package.json文件

好的,因此在进行了更多研究之后,我偶然发现Lerna,这使我可以做我想做的事情(到目前为止,我所看到的)。它需要特定的项目树设置,如下所示:

project_root/  node_modules/  packages/    components/ // Components shared between projects      components/       MyComponent.jsx      index.jsx  legacy/     output/      build.js // React 0.14 build     node_modules/     package.json // project specific dependencies     index.jsx // project specific entry     .babelrc  modern/     output/      build.js // React 16 build     node_modules/     package.json // project specific dependencies     index.jsx // project specific entry     .babelrc  package.json // contains devDependencies shared between projects  lerna.json  webpack.config.js  index.html

然后,在components / index.jsx中,我根据全局变量指定了针对不同版本的require命令:

if(PROJECT_SRC == "legacy"){    React = require('../legacy/node_modules/react');    ReactDOM = require('../legacy/node_modules/react-dom');} else {    React = require('../modern/node_modules/react');    ReactDOM = require('../modern/node_modules/react-dom');}

注意:这可能是不好的做法,但是目前唯一的方式是我可以在构建中包含不同的React版本。在整个项目更改为该模型之后,我将不得不查看这种方法会出现什么问题。

在webpack.config.js中,我配置了两个导出-
一个用于现代,一个用于传统。每个都指向一个不同的入口index.jsx文件,使用webpack.DefinePlugin将全局变量设置为“旧版”或“现代”,并指定要解析的通用组件模块的路径:

['node_modules',path.resolve(__dirname, 'components')]

一个项目输出的webpack.config看起来像这样:

{        entry: "./packages/legacy/index.jsx",        target: "web",         output:         { filename: "build.js", path: __dirname + "/packages/legacy/dist/", libraryTarget: "var", library: "lib_name"        },        devtool: "source-map",        resolve: { extensions: [".js", ".jsx", ".json"], modules: ['node_modules', path.resolve(__dirname, 'components')]        },        plugins: plugins_legacy,        module: { loaders: [     {         test: /.jsx?$/,         loader: "babel-loader",         exclude: /node_modules/     } ]        }      }

随时发表评论或指出问题,但我希望这对将来有所帮助!:)



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/388314.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号