这是我的webpack.config.js
static int[][] arrays = new[]
{
new[] {090, 010, 002, 007, 310, 104, 048, 610, 720},
new[] {456, 010, 002, 007, 087, 011, 345, 547, 800},
new[] {004, 089, 870, 011, 345, 547, 800, 001, 002}
};
static void Main()
{
SequentedArray[] sequentedArrays = arrays.Select(array => new SequentedArray(array)).ToArray();
foreach (var baseSequentedArray in sequentedArrays)
{
foreach (var comparisonSequentedArray in sequentedArrays)
{
if(baseSequentedArray == comparisonSequentedArray) continue;
var sameSequences = baseSequentedArray.FindSameSequences(comparisonSequentedArray);
foreach (var sameSequence in sameSequences)
{
Console.WriteLine(String.Join(", ", sameSequence.GetValues(baseSequentedArray.Array)));
}
}
}
}
class SequentedArray
{
public int[] Array { get; private set; }
public List<Sequence> Sequences { get; private set; }
public SequentedArray(int[] array)
{
Array = array;
Sequences = new List<Sequence>();
for (int endIndex = 1; endIndex < array.Length; endIndex++)
{
int sum = array[endIndex];
for (int startIndex = endIndex - 1; startIndex >= 0; startIndex--)
{
sum += array[startIndex];
Sequences.Add(new Sequence(startIndex, endIndex, sum));
}
}
}
public IEnumerable<Sequence> FindSameSequences(SequentedArray comparison)
{
var sameSequences = new List<Sequence>();
foreach (var sequence in Sequences)
{
foreach (var comparisonSequence in comparison.Sequences)
{
if (sequence.Sum == comparisonSequence.Sum &&
sequence.GetValues(Array).SequenceEqual(comparisonSequence.GetValues(comparison.Array)))
{
var smallerSequences = sameSequences.Where(existing => sequence.Covers(existing)).ToList();
foreach (var smallerSequence in smallerSequences)
{
sameSequences.Remove(smallerSequence);
}
sameSequences.Add(sequence);
}
}
}
return sameSequences;
}
}
class Sequence
{
public int StartIndex { get; private set; }
public int EndIndex { get; private set; }
public int Sum { get; private set; }
public Sequence(int startIndex, int endIndex, int sum)
{
StartIndex = startIndex;
EndIndex = endIndex;
Sum = sum;
}
public IEnumerable<int> GetValues(int[] array)
{
for (int i = StartIndex; i <= EndIndex; i++)
{
yield return array[i];
}
}
public bool Covers(Sequence comparison)
{
return StartIndex <= comparison.StartIndex && EndIndex >= comparison.EndIndex;
}
}
这是我的package.json
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
module.exports = {
entry: './src/index.tsx',
output: {
path: path.resolve(__dirname, "build"),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: "awesome-typescript-loader"
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: "./index.html"
})
]
}
我可以使用{
"name": "react-ts-todo",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"start": "webpack-dev-server --mode development"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.3.0",
"react-dom": "^16.3.0"
},
"devDependencies": {
"@types/react": "^16.1.0",
"@types/react-dom": "^16.0.4",
"awesome-typescript-loader": "^4.0.1",
"html-webpack-plugin": "^3.1.0",
"typescript": "^2.8.1",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13",
"webpack-dev-server": "^3.1.1"
}
}
轻松启动我的webpack服务器,但是当我对我的文件进行更改并尝试刷新时。我的webpack dev服务器因错误
nom start
我用Google搜索,发现了这个
https://github.com/s-panferov/awesome-typescript-loader/issues/541
但这对我来说没有明确的可操作解决方案。
答案 0 :(得分:1)
行。我找到了答案here。我们需要将令人敬畏的打字稿加载器升级到
"awesome-typescript-loader": "^5.0.0-1"
以下package.json工作正常。
{
"name": "react-ts-todo",
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"start": "webpack-dev-server --mode development"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"react": "^16.3.0",
"react-dom": "^16.3.0"
},
"devDependencies": {
"@types/react": "^16.1.0",
"@types/react-dom": "^16.0.4",
"awesome-typescript-loader": "^5.0.0-1",
"html-webpack-plugin": "^3.1.0",
"typescript": "^2.8.1",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13",
"webpack-dev-server": "^3.1.1"
}
}