简体   繁体   English

@ shopify / polaris项目如何从github仓库构建为npm依赖项?

[英]How does the @shopify/polaris project get built from github repo to npm dependency?

I'm interested in learning how the @shopify/polaris project in github is built and published to npm . 我对学习如何在github中构建@ shopify / polaris项目并将其发布到npm感兴趣。 My main questions are: 我的主要问题是:

  • How are the index.es.js and index.js files being generated? 如何生成index.es.jsindex.js文件? Are those being generated programmatically on my computer, or are they published to npm like this? 这些是在我的计算机上以编程方式生成的,还是这样发布到npm
  • What mechanism is preventing the files in the github repo from being downloaded when installed? 什么机制阻止安装时下载github存储库中的文件? I don't see a .npmignore in the repo. 我在.npmignore不到.npmignore

Below I have the files in the npm package, and the github, and you can see they're different. 下面,我在npm包和github中都有文件,您可以看到它们是不同的。

Here's what the polaris project looks like when it's installed via NPM / yarn. 这是通过NPM / yarn安装的polaris项目的外观。

.
├── CHANGELOG.md
├── README.md
├── index.es.js
├── index.js
├── package.json
├── src
├── styles
├── styles.css
├── styles.scss
└── types

Here's what the project looks like on github. 这是该项目在github上的样子。

.
├── CHANGELOG.md
├── README.md
├── circle.yml
├── config
├── documentation
├── examples
├── package.json
├── scripts
├── src
├── tests
├── tsconfig.json
├── tslint.json
└── yarn.lock

We use Rollup to generate the different entry files for Polaris. 我们使用汇总来为Polaris生成不同的条目文件。 You can see our generic config file here: https://github.com/Shopify/polaris/blob/master/config/rollup/index.js . 您可以在此处查看我们的通用配置文件: https : //github.com/Shopify/polaris/blob/master/config/rollup/index.js Note that it does all the work of compiling our TypeScript source files (using TypeScript and Babel), as well as kicking off the work required to bundle our CSS and icons as appropriate. 请注意,它完成了编译TypeScript源文件(使用TypeScript和Babel)的所有工作,并开始了将CSS和图标适当捆绑在一起所需的工作。 This config generator is then run three times, which you can see here: https://github.com/Shopify/polaris/blob/master/scripts/build.js#L36-L38 然后,此配置生成器将运行三次,您可以在此处查看: https : //github.com/Shopify/polaris/blob/master/scripts/build.js#L36-L38

  1. The main entry file ( .js , and spits out the CSS for our CDN) main条目文件( .js ,并为我们的CDN吐出CSS)
  2. The module entry file ( .es.js ) module条目文件( .es.js
  3. The embedded entry file embedded条目文件

We then copy these into their final locations for the NPM publish. 然后,将它们复制到NPM发布的最终位置。

As for how we control what files are in the NPM package, we use the files key in our package.json ; 至于我们如何控制NPM包中的files ,我们使用package.jsonfiles these are the relevant lines . 这些是相关的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM