Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 4921321

Browse files
rowandhsis0k0
authored andcommitted
feat: add support for passing params via --env to webpack (#204)
1 parent 3fb865d commit 4921321

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

Diff for: bin/ns-bundle

+10-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ if (!process.env.npm_config_argv) {
1515

1616
const escape = arg => `"${arg}"`;
1717
const isTnsCommand = flag => flag.endsWith("-app");
18+
const isEnvCommand = flag => flag.indexOf("env.") > -1;
1819
const shouldUglify = () => process.env.npm_config_uglify;
1920
const shouldSnapshot = (platform) => platform == "android" && require("os").type() != "Windows_NT" && process.env.npm_config_snapshot;
2021

@@ -34,7 +35,7 @@ function getTnsArgs(args) {
3435
"--nobundle",
3536
];
3637

37-
return args.filter(a => !other.includes(a) && !isTnsCommand(a));
38+
return args.filter(a => !other.includes(a) && !isTnsCommand(a) && !isEnvCommand(a));
3839
}
3940

4041
execute(options);
@@ -51,7 +52,7 @@ function execute(options) {
5152
() => cleanApp(platform),
5253
() => cleanSnapshotArtefacts(),
5354
() => cleanBuildArtifacts(platform),
54-
() => webpack(platform),
55+
() => webpack(platform, options.env),
5556
];
5657
}
5758

@@ -139,7 +140,7 @@ function cleanApp(platform) {
139140
});
140141
}
141142

142-
function webpack(platform) {
143+
function webpack(platform, env) {
143144
return new Promise(function (resolve, reject) {
144145
console.log(`Running webpack for ${platform}...`);
145146

@@ -148,6 +149,7 @@ function webpack(platform) {
148149
`--config=webpack.config.js`,
149150
`--progress`,
150151
`--env.${platform}`,
152+
...env.map(item => `--${item}`),
151153
shouldUglify() && `--env.uglify`,
152154
shouldSnapshot(platform) && `--env.snapshot`
153155
];
@@ -172,11 +174,16 @@ function getOptions(flags) {
172174
let options = {};
173175
options.platform = getPlatform(flags);
174176
options.command = getCommand(flags);
177+
options.env = getEnv(flags);
175178
options.bundle = !flags.includes("nobundle");
176179

177180
return options;
178181
}
179182

183+
function getEnv(flags) {
184+
return flags.filter(item => isEnvCommand(item));
185+
}
186+
180187
function getPlatform(flags) {
181188
if (flags.includes("android") && flags.includes("ios")) {
182189
throwError({message: "You cannot use both --android and --ios flags!"});

0 commit comments

Comments
 (0)