Javascript webpack:必须手动执行TSC才能解析模块

Javascript webpack:必须手动执行TSC才能解析模块,javascript,angular,webpack,Javascript,Angular,Webpack,我的完整webpack.config.js粘贴在下面以供参考。 如果我删除应用程序目录中的所有*.js文件,则webpack会抱怨以下错误: ../main.ts中出错 未找到模块:错误:无法解析“C:\Projects\Github\Panda\Panda.CoreService\wwwroot\ts”中的“./app/app.Module” @../main.ts 5:19-46 @多../main.ts 它看起来在正确的位置,错误中的相对路径看起来都是正确的 另一方面,如果我执行tsc,,

我的完整webpack.config.js粘贴在下面以供参考。 如果我删除应用程序目录中的所有
*.js
文件,则webpack会抱怨以下错误:

../main.ts中出错 未找到模块:错误:无法解析“C:\Projects\Github\Panda\Panda.CoreService\wwwroot\ts”中的“./app/app.Module” @../main.ts 5:19-46 @多../main.ts

它看起来在正确的位置,错误中的相对路径看起来都是正确的

另一方面,如果我执行
tsc
,然后执行
webpack
,则所有模块都会被找到并生成,没有任何问题。就好像webpack根本就没有编译打字脚本一样。我试过后退,但似乎无法解决

目录结构

tsconfig.json
wwwroot\ts\main.ts
wwwroot\ts\app\app.module.ts
wwwroot\ts\webpack\webpack.config.js
webpack.config.js

const path = require("path");
const webpack = require("webpack");
const extractTextPlugin = require("extract-text-webpack-plugin");

const config = {
    wwwroot: "../../../wwwroot",
    css: "../../../wwwroot/css",
    node: "../../../node_modules",
    admin: "../../../wwwroot/sass/src/"
};
config.scssInclude = [
    path.resolve(__dirname, config.node),
    path.resolve(__dirname, "../../../wwwroot")
];
console.log("------------------------------------------------------------");
console.log(config);
console.log("------------------------------------------------------------");

const configuration = {
    context: __dirname,
    entry: {
        "application": ["../main.ts"],
        "vendor": [
            "@angular/animations",
            "@angular/common",
            "@angular/common/http",
            "@angular/compiler",
            "@angular/core",
            "@angular/forms",
            "@angular/http",
            "@angular/platform-browser",
            "@angular/platform-browser-dynamic",
            "@angular/router",
            "ngx-logger",
            "jquery",
            "jquery-validation",
            "jquery-validation-unobtrusive",
            "bluebird",
            "moment",
            "ramda",
            "lodash",
            "reflect-metadata",
            "zone.js",
            "ng2-charts/ng2-charts",
            "ngx-bootstrap/dropdown",
            "ngx-bootstrap/tabs"
        ],
        "style": ["../../sass/src/application.scss"]
        //"site": ["../site/preload.js"],
        //"bootstrap": ["../../sass/bootstrap.scss"],
        //"print": ["../../sass/admin/print.scss"]
    },
    output: {
        path: path.join(__dirname, "../"),
        filename: "[name].js",
        chunkFilename: "[name].js",
        publicPath: "ts/"
    },
    devtool: "source-map",
    plugins: [
        new webpack.LoaderOptionsPlugin({
            debug: true
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name: "vendor",
            filename: "vendor.js"
        }),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery",
            "window.jquery": "jquery",
            //Promise: "bluebird",
            _: "lodash"
        }),
        new extractTextPlugin({
            // disable: false,
            disable: process.env.NODE_ENV != "production",
            filename: "../../wwwroot/css/[name].css",
            allChunks: true
        })
    ],
    resolve:
    {
        alias: {
            typeahead: "typeahead.js"
        }
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: ["ts-loader"],
                exclude: /(node_modules)/
            },
            {
                test: /\.scss|\.css$/,
                use: extractTextPlugin.extract({
                    use: [
                        {
                            loader: "css-loader",
                            options: {
                                includePaths: config.scssInclude,
                                sourceMap: true
                            }
                        },
                        {
                            loader: "sass-loader",
                            options: {
                                sourceMap: true,
                                sourceMapContents: true,
                                precision: 10,
                                includePaths: config.scssInclude,
                                outputStyle: "nested"
                            }
                        }
                    ],
                    fallback: "style-loader"
                })
            },
            {
                test: /\.(eot|ttf|woff|woff2|svg)$/,
                exclude: [/wwwroot(\\|\/)fonts/,/wwwroot(\\|\/)images/],
                loader: "file-loader",
                options: {
                    name: "[name].[ext]",
                    outputPath: "../fonts/",
                    publicPath: "/"
                }
            },
            {
                test: /\.(eot|ttf|woff|woff2|svg)$/,
                include: /wwwroot(\\|\/)fonts/,
                loader: "file-loader",
                options: {
                    emitFile: false,
                    name: "[name].[ext]",
                    outputPath: "../fonts/",
                    publicPath: "/"
                }
            },
            {
                test: /\.(svg|png|jpeg|gif)$/,
                include: /wwwroot(\\|\/)images/,
                exclude: /node_modules/,
                loader: "file-loader",
                options: {
                    emitFile: false,
                    name: "[name].[ext]",
                    publicPath: "../images/"
                }
            },
            {
                test: /\.(svg|png|jpeg|gif)$/,
                include: /sass(\\|\/)img/,
                exclude: /node_modules/,
                loader: "file-loader",
                options: {
                    emitFile: true,
                    name: "[name].[ext]",
                    outputPath: "../images/template/",
                    publicPath: "/"
                }
            },
            {
                test: require.resolve("jquery"),
                use: [
                    { loader: "expose-loader", options: "jQuery" },
                    { loader: "expose-loader", options: "$" }
                ]
            }
        ]
    }
};

console.log("------------------------------------------------------------");
console.log(configuration.module.rules);
console.log("------------------------------------------------------------");
module.exports = configuration;
import { enableProdMode } from "@angular/core";
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";

import { AppModule } from "./app/app.module";
import { environment } from "./environments/environment";

/* additional scripts */
import "script-loader!./lib/jquery-resizable.js"
import "script-loader!./lib/tagsuggest.js"
import "./lib/tagsuggest.scss"

import "../fonts/proxima-nova.css";
import "../fonts/roboto.css";

// font awesome
import "font-awesome/scss/font-awesome.scss";

// simple line icons.
import "simple-line-icons/scss/simple-line-icons.scss";

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);
main.ts

const path = require("path");
const webpack = require("webpack");
const extractTextPlugin = require("extract-text-webpack-plugin");

const config = {
    wwwroot: "../../../wwwroot",
    css: "../../../wwwroot/css",
    node: "../../../node_modules",
    admin: "../../../wwwroot/sass/src/"
};
config.scssInclude = [
    path.resolve(__dirname, config.node),
    path.resolve(__dirname, "../../../wwwroot")
];
console.log("------------------------------------------------------------");
console.log(config);
console.log("------------------------------------------------------------");

const configuration = {
    context: __dirname,
    entry: {
        "application": ["../main.ts"],
        "vendor": [
            "@angular/animations",
            "@angular/common",
            "@angular/common/http",
            "@angular/compiler",
            "@angular/core",
            "@angular/forms",
            "@angular/http",
            "@angular/platform-browser",
            "@angular/platform-browser-dynamic",
            "@angular/router",
            "ngx-logger",
            "jquery",
            "jquery-validation",
            "jquery-validation-unobtrusive",
            "bluebird",
            "moment",
            "ramda",
            "lodash",
            "reflect-metadata",
            "zone.js",
            "ng2-charts/ng2-charts",
            "ngx-bootstrap/dropdown",
            "ngx-bootstrap/tabs"
        ],
        "style": ["../../sass/src/application.scss"]
        //"site": ["../site/preload.js"],
        //"bootstrap": ["../../sass/bootstrap.scss"],
        //"print": ["../../sass/admin/print.scss"]
    },
    output: {
        path: path.join(__dirname, "../"),
        filename: "[name].js",
        chunkFilename: "[name].js",
        publicPath: "ts/"
    },
    devtool: "source-map",
    plugins: [
        new webpack.LoaderOptionsPlugin({
            debug: true
        }),
        new webpack.optimize.CommonsChunkPlugin({
            name: "vendor",
            filename: "vendor.js"
        }),
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery",
            "window.jQuery": "jquery",
            "window.jquery": "jquery",
            //Promise: "bluebird",
            _: "lodash"
        }),
        new extractTextPlugin({
            // disable: false,
            disable: process.env.NODE_ENV != "production",
            filename: "../../wwwroot/css/[name].css",
            allChunks: true
        })
    ],
    resolve:
    {
        alias: {
            typeahead: "typeahead.js"
        }
    },
    module: {
        rules: [
            {
                test: /\.ts$/,
                use: ["ts-loader"],
                exclude: /(node_modules)/
            },
            {
                test: /\.scss|\.css$/,
                use: extractTextPlugin.extract({
                    use: [
                        {
                            loader: "css-loader",
                            options: {
                                includePaths: config.scssInclude,
                                sourceMap: true
                            }
                        },
                        {
                            loader: "sass-loader",
                            options: {
                                sourceMap: true,
                                sourceMapContents: true,
                                precision: 10,
                                includePaths: config.scssInclude,
                                outputStyle: "nested"
                            }
                        }
                    ],
                    fallback: "style-loader"
                })
            },
            {
                test: /\.(eot|ttf|woff|woff2|svg)$/,
                exclude: [/wwwroot(\\|\/)fonts/,/wwwroot(\\|\/)images/],
                loader: "file-loader",
                options: {
                    name: "[name].[ext]",
                    outputPath: "../fonts/",
                    publicPath: "/"
                }
            },
            {
                test: /\.(eot|ttf|woff|woff2|svg)$/,
                include: /wwwroot(\\|\/)fonts/,
                loader: "file-loader",
                options: {
                    emitFile: false,
                    name: "[name].[ext]",
                    outputPath: "../fonts/",
                    publicPath: "/"
                }
            },
            {
                test: /\.(svg|png|jpeg|gif)$/,
                include: /wwwroot(\\|\/)images/,
                exclude: /node_modules/,
                loader: "file-loader",
                options: {
                    emitFile: false,
                    name: "[name].[ext]",
                    publicPath: "../images/"
                }
            },
            {
                test: /\.(svg|png|jpeg|gif)$/,
                include: /sass(\\|\/)img/,
                exclude: /node_modules/,
                loader: "file-loader",
                options: {
                    emitFile: true,
                    name: "[name].[ext]",
                    outputPath: "../images/template/",
                    publicPath: "/"
                }
            },
            {
                test: require.resolve("jquery"),
                use: [
                    { loader: "expose-loader", options: "jQuery" },
                    { loader: "expose-loader", options: "$" }
                ]
            }
        ]
    }
};

console.log("------------------------------------------------------------");
console.log(configuration.module.rules);
console.log("------------------------------------------------------------");
module.exports = configuration;
import { enableProdMode } from "@angular/core";
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";

import { AppModule } from "./app/app.module";
import { environment } from "./environments/environment";

/* additional scripts */
import "script-loader!./lib/jquery-resizable.js"
import "script-loader!./lib/tagsuggest.js"
import "./lib/tagsuggest.scss"

import "../fonts/proxima-nova.css";
import "../fonts/roboto.css";

// font awesome
import "font-awesome/scss/font-awesome.scss";

// simple line icons.
import "simple-line-icons/scss/simple-line-icons.scss";

if (environment.production) {
  enableProdMode();
}

platformBrowserDynamic().bootstrapModule(AppModule);

默认情况下,网页包根本无法识别
*.ts
文件。 我找到了解决办法

webpack实际上只是在编译
js
文件时绑定这些文件,因为这是默认行为

我需要在解析部分中包含
*.ts.

resolve:
{
    extensions: [".ts", ".js", ".json"],
},