From f37eda619b284a217be2318af048035c1763b675 Mon Sep 17 00:00:00 2001 From: Joel Nation Date: Tue, 24 Aug 2021 15:19:57 +1000 Subject: [PATCH] Added webpack support for Node Added the ability to use a compiled dist folder script rather than the full code. Reduces overall file size and allows you to have test code that isn't compiled and sent to the server --- config/version.go | 2 +- langs/node.go | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config/version.go b/config/version.go index 3d96fddd..2cd20c40 100644 --- a/config/version.go +++ b/config/version.go @@ -9,7 +9,7 @@ import ( ) // Version of Fn CLI -var Version = "0.6.8" +var Version = "0.6.9" func GetVersion(versionType string) string { base := "https://github.com/fnproject/cli/releases" diff --git a/langs/node.go b/langs/node.go index 038943c7..53dbf355 100644 --- a/langs/node.go +++ b/langs/node.go @@ -98,7 +98,9 @@ func (h *NodeLangHelper) Entrypoint() (string, error) { func (h *NodeLangHelper) DockerfileBuildCmds() []string { r := []string{} // skip npm -install if node_modules is local - allows local development - if exists("package.json") && !exists("node_modules") { + if exists("dist") { + // Do nothing + } else if exists("package.json") && !exists("node_modules") { if exists("package-lock.json") { r = append(r, "ADD package-lock.json /function/") } @@ -112,7 +114,13 @@ func (h *NodeLangHelper) DockerfileBuildCmds() []string { } func (h *NodeLangHelper) DockerfileCopyCmds() []string { + // If they have a dist folder (likely from webpack) let's just include that + if exists("dist") { + r := []string{"ADD dist/main.js /function/func.js"} + return r + } // excessive but content could be anything really + r := []string{"ADD . /function/"} if exists("package.json") && !exists("node_modules") { r = append(r, "COPY --from=build-stage /function/node_modules/ /function/node_modules/")