diff --git a/lib/build.js b/lib/build.js index f1130872..6439179c 100644 --- a/lib/build.js +++ b/lib/build.js @@ -22,6 +22,14 @@ function webpackConfig(dir, additionalConfig) { ]; } + var functionsDir = config.build.functions || config.build.Functions; + var functionsPath = path.join(process.cwd(), functionsDir); + var dirPath = path.join(process.cwd(), dir); + + if (dirPath === functionsPath) { + throw new Error("Function source and publish folder should be in different locations"); + } + var webpackConfig = { module: { rules: [ @@ -35,21 +43,18 @@ function webpackConfig(dir, additionalConfig) { } ] }, - context: path.join(process.cwd(), dir), + context: dirPath, entry: {}, target: "node", plugins: [new webpack.IgnorePlugin(/vertx/)], output: { - path: path.join( - process.cwd(), - config.build.functions || config.build.Functions - ), + path: functionsPath, filename: "[name].js", libraryTarget: "commonjs" }, devtool: false }; - fs.readdirSync(path.join(process.cwd(), dir)).forEach(function(file) { + fs.readdirSync(dirPath).forEach(function(file) { if (file.match(/\.js$/)) { var name = file.replace(/\.js$/, ""); webpackConfig.entry[name] = "./" + name;