-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.rescriptsrc.js
82 lines (76 loc) · 2.22 KB
/
.rescriptsrc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const path = require("path");
const {
appendWebpackPlugin,
editWebpackPlugin
} = require("@rescripts/utilities");
const WorkerPlugin = require("worker-plugin");
const set = require("lodash.set");
const get = require("lodash.get");
const fs = require("fs");
const isEmpty = require("is-empty");
const requireES6 = require("esm")(module);
const { alias, jestModuleNameMapper } = require("./shared-config");
const mw = fn => Object.assign(fn, { isMiddleware: true });
const addAlias = mw(config => {
const existingAlias = get(config, "resolve.alias", {});
config = set(
config,
"resolve.alias",
Object.assign({}, existingAlias, alias)
);
return config;
});
const addWorkerPlugin = mw(config =>
appendWebpackPlugin(new WorkerPlugin(), config)
);
const addAWSConfig = mw(config => {
const env = process.env.REACT_APP_FORCE_ENV || process.env.NODE_ENV;
// Check if aws-exports.js exists, otherwise, aws-exports.dev.js or aws-exports.prod.js
let awsConfigImport = {};
const awsConfigEnv =
process.env.AWS_AMPLIFY_ENV || (env === "production" ? "prod" : "dev");
if (
fs.existsSync(path.resolve(__dirname, `./aws-exports.${awsConfigEnv}.js`))
) {
awsConfigImport = requireES6(`./aws-exports.${awsConfigEnv}.js`);
} else if (fs.existsSync(path.resolve(__dirname, "./aws-exports.js"))) {
awsConfigImport = requireES6(`./aws-exports.js`);
}
const awsConfig = isEmpty(awsConfigImport.default)
? awsConfigImport
: awsConfigImport.default;
if (isEmpty(awsConfig)) {
throw new Error(
"Cannot find AWS Config. Please copy/symlink your 'aws-exports.js' from Amplify Environment/Directory into this project's root directory, or add AWS Environment variables."
);
}
config = editWebpackPlugin(
p => {
p.definitions["process.env"].AWS_CONFIG = JSON.stringify(awsConfig);
return p;
},
"DefinePlugin",
config
);
return config;
});
module.exports = [
["use-babel-config", ".babelrc.js"],
["use-eslint-config", ".eslintrc.js"],
{
jest: config => {
config.moduleNameMapper = {
...config.moduleNameMapper,
...jestModuleNameMapper
};
config.transform["^.+\\.(js|jsx|ts|tsx)$"] = path.resolve(
__dirname,
"./jest.transform.js"
);
return config;
}
},
addAlias,
addWorkerPlugin,
addAWSConfig
];