Node.js: Difference between revisions
imported>Zauberpony introduce direnv as antoher possibility |
imported>Makefu add packaging with yarn2nix |
||
Line 1: | Line 1: | ||
__TOC__ | __TOC__ | ||
{{expansion}} | {{expansion}} | ||
== Packaging == | |||
=== Package with yarn2nix === | |||
yarn2nix uses the yarn nodejs tool to create a file called yarn.lock, which in return can be used by yarn2nix to generate a usable yarn expression. | |||
This is what was needed to convert a small application server [https://git.shackspace.de/rz/muellshack/tree/3be09715911628b164fa1cf346387555ca26a5b1 shackspace muellshack]: | |||
<syntaxHighlight lang=console> | |||
$ nix-shell -p yarn yarn2nix | |||
$ yarn install | |||
# creates yarn.lock | |||
$ yarn2nix > yarn.nix | |||
$ vim package.json | |||
# add: "bin": "app.js", | |||
$ cat > default.nix <<EOF | |||
with (import <nixpkgs> {}); | |||
rec { | |||
muellshack = mkYarnPackage { | |||
name = "muellshack"; | |||
src = ./.; | |||
packageJSON = ./package.json; | |||
yarnLock = ./yarn.lock; | |||
yarnNix = ./yarn.nix; | |||
}; | |||
} | |||
EOF | |||
$ sed -i '1i#!/usr/bin/env node' app.js | |||
$ chmod +x app.js | |||
$ nix-build | |||
$ result/bin/muellshack | |||
</syntaxHighlight> | |||
The complete diff can be found at [https://git.shackspace.de/rz/muellshack/commit/f5e498acd47695c4947dc1b5ddebfad2eee8d653 the respective diff] | |||
== FAQ == | == FAQ == |