Skip to content

Commit 97f1633

Browse files
committed
#9 Remove the cli argument of external configuration file when it's not necessary
1 parent 163a649 commit 97f1633

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/Webpack/ArgumentsHelper.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ internal class ArgumentsHelper {
1313
/// <summary>
1414
/// Creates and returns the appropriate arguments list for the webpack based on the provided options
1515
/// </summary>
16-
public static string GetWebpackArguments(string rootPath, WebpackOptions options) {
17-
var result = new StringBuilder(DefaultDevFile);
16+
public static string GetWebpackArguments(string rootPath, WebpackOptions options, bool includeDefaultConfigFile) {
17+
var result = new StringBuilder();
18+
if(includeDefaultConfigFile) {
19+
result.Append(DefaultDevFile);
20+
}
1821
if (options.HandleStyles && options.StylesTypes.Any()) {
1922
if (options.StylesTypes.Contains(StylesType.Css)) {
2023
result.Append(CssFiles);

src/Webpack/Webpack.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ public WebPackMiddlewareOptions Execute(WebpackOptions options) {
3030
EnsuereNodeModluesInstalled(options.EnableHotLoading, logger);
3131
logger.LogInformation($"All node modules are properly installed");
3232

33-
CreateWebpackConfigurationFile(options);
33+
var includeDefaultConfigFile = CreateWebpackConfigurationFile(options);
3434

3535
logger.LogInformation($"{toolToExecute} Execution started");
3636
try {
37-
var arguments = ArgumentsHelper.GetWebpackArguments(_webRootPath, options);
37+
var arguments = ArgumentsHelper.GetWebpackArguments(_webRootPath, options, includeDefaultConfigFile);
3838
logger.LogInformation($"{toolToExecute} is called with these arguments: {arguments}");
3939
Process process = new Process();
4040
process.StartInfo = new ProcessStartInfo() {
@@ -109,10 +109,7 @@ private static string GetNodeExecutable(string module) {
109109
return executable;
110110
}
111111

112-
private static void CreateWebpackConfigurationFile(WebpackOptions options) {
113-
if (!Directory.Exists("webpack")) {
114-
Directory.CreateDirectory("webpack");
115-
}
112+
private static bool CreateWebpackConfigurationFile(WebpackOptions options) {
116113
var presets = new List<string>() {
117114
"es2015"
118115
};
@@ -146,6 +143,9 @@ private static void CreateWebpackConfigurationFile(WebpackOptions options) {
146143
};
147144
// Create the external configuration file only if we need to use babel-loader
148145
if (loaders.Count > 0) {
146+
if (!Directory.Exists("webpack")) {
147+
Directory.CreateDirectory("webpack");
148+
}
149149
var jsonResult = JsonConvert.SerializeObject(exports,
150150
new JsonSerializerSettings {
151151
Formatting = Formatting.Indented,
@@ -157,7 +157,9 @@ private static void CreateWebpackConfigurationFile(WebpackOptions options) {
157157
streamWriter.WriteLine(fileContent);
158158
}
159159
}
160+
return true;
160161
}
162+
return false;
161163
}
162164

163165
}

0 commit comments

Comments
 (0)