Skip to content

Commit ad58839

Browse files
authored
Merge pull request #98 from schiehll/find-babelrc
Check for babelrc up from given functions folder
2 parents c96cb13 + 986e122 commit ad58839

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/build.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,27 @@ function getBabelTarget(envConfig) {
1313
return unknown ? "6.10" : current.replace(/^nodejs/, "");
1414
}
1515

16+
function haveBabelrc(functionsDir) {
17+
const cwd = process.cwd();
18+
19+
return (
20+
fs.existsSync(path.join(cwd, ".babelrc")) ||
21+
functionsDir.split("/").reduce((foundBabelrc, dir) => {
22+
if (foundBabelrc) return foundBabelrc;
23+
24+
const indexOf = functionsDir.indexOf(dir);
25+
const dirToSearch = functionsDir.substr(0, indexOf);
26+
27+
return fs.existsSync(path.join(cwd, dirToSearch, ".babelrc"));
28+
}, false)
29+
);
30+
}
31+
1632
function webpackConfig(dir, additionalConfig) {
1733
var config = conf.load();
1834
var envConfig = config.build.environment || config.build.Environment || {};
1935
var babelOpts = { cacheDirectory: true };
20-
if (!fs.existsSync(path.join(process.cwd(), ".babelrc"))) {
36+
if (!haveBabelrc(dir)) {
2137
babelOpts.presets = [
2238
["@babel/preset-env", { targets: { node: getBabelTarget(envConfig) } }]
2339
];
@@ -48,7 +64,7 @@ function webpackConfig(dir, additionalConfig) {
4864
var webpackConfig = {
4965
mode: "production",
5066
resolve: {
51-
extensions: ['.wasm', '.mjs', '.js', '.json', '.ts']
67+
extensions: [".wasm", ".mjs", ".js", ".json", ".ts"]
5268
},
5369
module: {
5470
rules: [

0 commit comments

Comments
 (0)