-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hot-reload using webpack 5 #162
Changes from all commits
546ffbe
267fe0c
e6b5e06
bd6c4b5
f7e8c05
cbfa588
4f4b01a
a4b9158
e15e563
92f0af0
ba0e3b4
6c165c4
e1db8a5
0102b7a
4fce445
6d81313
6d6b390
713802d
367f442
37ab8b2
f2cd1c8
5b86d0a
cb50b33
024a7bb
b939010
e5159f5
3601f20
09b1773
36bf792
316fced
c702e9e
5fc575f
af57090
3fdebc6
ce94001
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using WebViewControl; | ||
|
||
namespace ReactViewControl { | ||
internal class FileDependenciesProvider : IModuleDependenciesProvider { | ||
|
||
private const string JsEntryFileExtension = ".js.entry"; | ||
private const string CssEntryFileExtension = ".css.entry"; | ||
|
||
private readonly string sourcePath; | ||
|
||
public FileDependenciesProvider(string sourcePath) { | ||
this.sourcePath = sourcePath; | ||
|
||
DependencyJsSourcesCache = new Lazy<string[]>(() => GetDependenciesFromEntriesFile(JsEntryFileExtension)); | ||
CssSourcesCache = new Lazy<string[]>(() => GetDependenciesFromEntriesFile(CssEntryFileExtension)); | ||
} | ||
|
||
public string[] GetCssDependencies() => CssSourcesCache.Value; | ||
|
||
public string[] GetJsDependencies() => DependencyJsSourcesCache.Value; | ||
|
||
private Lazy<string[]> DependencyJsSourcesCache { get; } | ||
private Lazy<string[]> CssSourcesCache { get; } | ||
|
||
private string[] GetDependenciesFromEntriesFile(string extension) { | ||
var entriesFilePath = Path.Combine(Path.GetDirectoryName(sourcePath), Path.GetFileNameWithoutExtension(sourcePath) + extension); | ||
var resource = entriesFilePath.Split(new[] { Path.DirectorySeparatorChar }, StringSplitOptions.RemoveEmptyEntries); | ||
|
||
using (var stream = GetResourceStream(resource)) { | ||
if (stream != null) { | ||
using (var reader = new StreamReader(stream)) { | ||
var allEntries = reader.ReadToEnd(); | ||
if (!string.IsNullOrEmpty(allEntries)) { | ||
return allEntries.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); | ||
} | ||
} | ||
} | ||
} | ||
return Array.Empty<string>(); | ||
} | ||
|
||
private Stream GetResourceStream(string[] resource) => ResourcesManager.TryGetResourceWithFullPath(resource.First(), resource); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace ReactViewControl { | ||
public interface IModuleDependenciesProvider { | ||
string[] GetCssDependencies(); | ||
|
||
string[] GetJsDependencies(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace ReactViewControl; | ||
|
||
public interface IModuleDependenciesProviderFactory { | ||
|
||
IModuleDependenciesProvider CreateModuleDependenciesProvider(string sourcePath); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
namespace ReactViewControl; | ||
|
||
public class ModuleDependenciesProviderFactory : IModuleDependenciesProviderFactory { | ||
|
||
public static IModuleDependenciesProviderFactory Instance { get; private set; } = new ModuleDependenciesProviderFactory(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public static IModuleDependenciesProviderFactory Instance { get; set; } = new ModuleDependenciesProviderFactory(); |
||
|
||
public static void SetInstance(IModuleDependenciesProviderFactory factory) { | ||
Instance = factory; | ||
} | ||
Comment on lines
+7
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
|
||
public virtual IModuleDependenciesProvider CreateModuleDependenciesProvider(string sourcePath) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. public IModuleDependenciesProvider CreateModuleDependenciesProvider(string sourcePath) { |
||
return new FileDependenciesProvider(sourcePath); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public sealed class