Skip to content

Commit

Permalink
Yarn Build Plugin for Netlify
Browse files Browse the repository at this point in the history
  • Loading branch information
gigincg committed Jun 8, 2022
1 parent 6da55e4 commit f74099a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
24 changes: 24 additions & 0 deletions .netlify/netlify-plugin-yarn/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {
onPreBuild: async ({ utils: { build, run } }) => {
const cacheDir = ".yarn_cache";

process.env["YARN_CACHE_FOLDER"] = `${process.env.HOME}/${cacheDir}`;
process.env[
"NETLIFY_CACHE_DIR"
] = `${process.env.NETLIFY_BUILD_BASE}/cache`;

try {
await run.command(
`mv ${process.env.NETLIFY_CACHE_DIR}/${cacheDir} ${process.env.YARN_CACHE_FOLDER}`
);
} catch (error) {
console.log("No yarn cache found");
}

try {
await run.command("corepack enable");
} catch (error) {
return build.failBuild(error);
}
},
};
2 changes: 2 additions & 0 deletions .netlify/netlify-plugin-yarn/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: netlify-plugin-yarn
inputs: []
17 changes: 12 additions & 5 deletions netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,21 @@ command = "CI='' yarn run build"

## Yarn 3 cache does not work out of the box as of Jan 2022. Context:
## https://github.com/netlify/build/issues/1535#issuecomment-1021947989
[build.environment]
NETLIFY_USE_YARN = "true"
YARN_VERSION = "3.2.1"
YARN_FLAGS = "--check-cache"
YARN_CACHE_FOLDER = "/opt/buildhome/.yarn_cache"
## [build.environment]
## NETLIFY_USE_YARN = "true"
## YARN_VERSION = "3.2.1"
## YARN_FLAGS = "--check-cache"
## YARN_CACHE_FOLDER = "/opt/buildhome/.yarn_cache"
## YARN_ENABLE_GLOBAL_CACHE = "true"
## YARN_GLOBAL_FOLDER = "/opt/buildhome/.yarn_cache"

[build.environment]
NODE_VERSION = "16"
NPM_FLAGS = "--version"

[[plugins]]
package = "/.netlify/netlify-plugin-yarn"

[[redirects]]
from = "/api/*"
to = "https://careapi.coronasafe.in/api/:splat"
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -244,5 +244,9 @@
"react-app"
]
},
"engines": {
"node": "16.x",
"yarn": "3.2.1"
},
"packageManager": "[email protected]"
}

0 comments on commit f74099a

Please sign in to comment.