简体   繁体   English

直接在 Github 仓库中包含 JS 插件文件?

[英]Including JS plugin files directly in Github repository?

I am relatively new to using git and GitHub, and I am working on my personal website.我对使用 git 和 GitHub 比较陌生,我正在我的个人网站上工作。 I am using the JS plugin Slick, a responsive carousel feature.我正在使用 JS 插件 Slick,这是一个响应式轮播功能。 I downloaded all of the necessary files and stored them within my local repo.我下载了所有必要的文件并将它们存储在我的本地存储库中。 The size and content of the Slick zip folder is much larger than the files for my site at the moment, so when syncing with GitHub this makes my project appear as 75% Javascript, whereas the actual website is not.目前,Slick zip 文件夹的大小和内容比我网站的文件大得多,因此当与 GitHub 同步时,这会使我的项目显示为 75% Javascript,而实际网站则不然。

Am I doing this correctly, storing the files for my JS plugin directly within my repository folder?我这样做是否正确,将我的 JS 插件的文件直接存储在我的存储库文件夹中? Or should I be using some other method to implement Slick on my site?或者我应该使用其他方法在我的网站上实现 Slick 吗? Or is this just something I should not be worried about?或者这只是我不应该担心的事情? Thanks谢谢

If you're just using one library, manually storing it in your Git repo is fine.如果您只使用一个库,手动将其存储在您的 Git 存储库中就可以了。 You'd have to manually update the files if a new version is released, but that's not a big deal for one library.如果发布了新版本,您必须手动更新文件,但这对于一个库来说并不是什么大问题。 (And you might not even care about updates to this library). (你甚至可能不关心这个库的更新)。

However if you're using more than one library, I'd highly recommend using Node Package Manager (NPM) and a build tool like Webpack.但是,如果您使用多个库,我强烈建议您使用 Node Package Manager (NPM) 和像 Webpack 这样的构建工具。

Here's an article that introduces these tools (plus a few others): https://medium.com/front-end-hacking/what-are-npm-yarn-babel-and-webpack-and-how-to-properly-use-them-d835a758f987这是一篇介绍这些工具(以及其他一些工具)的文章: https : //medium.com/front-end-hacking/what-are-npm-yarn-babel-and-webpack-and-how-to-properly-使用他们-d835a758f987

For using git, you should store your dependencies in a folder that is in your .gitignore .要使用 git,您应该将依赖项存储在.gitignore中的文件夹中。 If you install browserify or another similar tool like webpack, you can use the npm package manager to create a dependency list file with npm init that allows for easy package installation with npm install by anyone.如果您安装browserify或类似的WebPack其他类似工具,你可以使用NPM软件包管理器创建一个依赖列表文件npm init ,允许方便包安装npm install任何人。 You can install packages slick with npm install --save slick-carousel and use them with require() in your main js file.您可以使用npm install --save slick-carousel npm install --save软件包,并在主 js 文件中将它们与require()一起使用。 Then, take your js file and run browserify jsfile.js -o outputfile.js and it will package your js and your dependencies together to be used by the browser然后,获取您的 js 文件并运行browserify jsfile.js -o outputfile.js ,它将把您的 js 和您的依赖项打包在一起以供浏览器使用

When uploading to your git repo, add a .gitignore like this one for Node .当上传到你的 git repo 时, 为 Node添加一个像 这样.gitignore This prevents your dependencies from being uploaded to the repo and instead when someone wants to run your project, they must run npm install to get all the dependencies.这可以防止您的依赖项上传到存储库,而当有人想要运行您的项目时,他们必须运行npm install以获取所有依赖项。

Browserify gives an output JS file you add to your web server, the name of this file should be put in your .gitignore as well. Browserify 提供您添加到 Web 服务器的输出 JS 文件,该文件的名称也应放在您的.gitignore中。 Your code is stored in the js file you pass to browserify and other people can still access it without the output file, but they need to run the browserify command to package your code.您的代码存储在您传递给 browserify 的 js 文件中,其他人仍然可以在没有输出文件的情况下访问它,但是他们需要运行 browserify 命令来打包您的代码。

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

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