Skip to content

fabioricali/nuk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

66 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

💣nuk

A package manager that installs only what you need.

Motivation

It often happens to add resources hosted on CDN to websites or web applications. CDNs, I know, are very convenient and quick to include a lib. But how safe is it to do it? How many times does it happen that these are unreachable for traffic reasons? For example, it happens to me with unkpg.com. Get the files from the node_modules folder? No! it is not done. Too big. So I thought of creating a simple package manager (I don't know if I can call it that) that simply downloads the resources you want in a folder.

The files should be kept "local". If you have your own CDN, even better. 😎

Installation

$ npm install -g nuk

Usage

Do you need to install only the UMD version of React?

$ nuk install react/umd

After this a vendors/react/umd folder will be created with only the files of the React umd folder present in the package on npm. Now, you can include your file:

<script src="vendors/react/umd/react.production.min.js"></script>

PS: if it doesn't already exist, a configuration file called nuk.json will be automatically created. This serves as a configuration.

Please don't remove nuk-lock.json useful for keeping track of installed packages.

You can also install multiple packages

$ nuk install react/umd doz/dist

Obviously you can install the version you want (recommended):

$ nuk install react@16.12.0/umd

For updating the package to the latest version use update

$ nuk update react

If you want to know quickly which files you can include in a given package then you can use list:

$ nuk list react

You will receive an output like this:

nuk install react/cjs
nuk install react/cjs/react.development.js
nuk install react/cjs/react.production.min.js
nuk install react/index.js
nuk install react/index.min.js
nuk install react/umd
nuk install react/umd/react.development.js
nuk install react/umd/react.production.min.js
nuk install react/umd/react.profiling.min.js

I understand that inserting so many scripts into your html page could be tiring. So nuk gives you another command called "bundle". This command will only take minified files that conventionally have "min." in the file name and will concatenate them into one file bundle.js and bundle.css. It does nothing else. It is not a real bundler. The files will be created inside the "vendors" folder.

$ nuk bundle

if you need to exclude certain files or change the order in which nuk generates the bundle then you can add the "bundleFiles" property to your nuk.json:

{
  "bundleFiles": [
    "swiper/css/swiper.min.css",
    "react/umd/react.production.min.js"  
  ]
}

It will provide two files:

  • vendors/bundle.js
  • vendors/bundle.css

So, you can include just this:

<script src="vendors/bundle.js"></script>
<link href="vendors/bundle.css" rel="stylesheet" type="text/css">

if you need to diversify the bundles you can then do so:

{
    "bundleFiles": {
        "bundle1": [
            "swiper/css/swiper.min.css",
            "react/umd/react.production.min.js"
        ],
        "bundle2": [
            "react/umd/react.profiling.min.js"
        ]
    }
}

In this case it will provide three files:

  • vendors/bundle1.js
  • vendors/bundle1.css
  • vendors/bundle2.js

Do you need to uninstall?

$ nuk uninstall react

if you need to change the name of the vendors folder then add this property to the nuk.json file:

{
  "folderName": "my-vendors"
}

Changelog

You can view the changelog here

License

nuk is open-sourced software licensed under the MIT license

Author

Fabio Ricali

About

A package manager that installs only what you need.

Resources

Stars

Watchers

Forks

Packages

No packages published