所以现在我正在使用一个原型,我们使用webpack(用于构建.tsx文件和复制.html文件)和webpack dev server之间的组合来提供开发服务.您可以假设,我们也将React和ReactDOM用作两个库依赖项.我们当前的构建输出是以下 struct :

dist
    -favicon.ico
    -index.html
    -main.js
    -main.js.map // for source-mapping between tsx / js files

这会将所有模块(包括库依赖项)放在一个大的Bundle 文件中.我希望最终结果如下:

dist
    -favicon.ico
    -index.html
    -appName.js
    -appName.min.js
    -react.js
    -react.min.js
    -reactDOM.js
    -reactDOM.min.js

我对索引中的每个库都有引用.html和中的导入语句.tsx文件.所以我的问题是...

当前网页包.配置:

var webpack = require("webpack"); // Assigning node package of webpack dependency to var for later utilization
var path = require("path"); // // Assigning node package of path dependency to var for later utilization

module.exports = {
    entry:  [
                "./wwwroot/app/appName.tsx", // Starting point of linking/compiling Typescript and dependencies, will need to add separate entry points in case of not deving SPA
                "./wwwroot/index.html", // Starting point of including HTML and dependencies, will need to add separate entry points in case of not deving SPA
                "./wwwroot/favicon.ico" // Input location for favicon
            ],
    output: {
        path: "./dist/", // Where we want to host files in local file directory structure
        publicPath: "/", // Where we want files to appear in hosting (eventual resolution to: https://localhost:4444/)
        filename: "appName.js" // What we want end compiled app JS file to be called
    },

    // Enable sourcemaps for debugging webpack's output.
    devtool: "source-map",

    devServer: {
        contentBase: './dist', // Copy and serve files from dist folder
        port: 4444, // Host on localhost port 4444
        // https: true, // Enable self-signed https/ssl cert debugging
        colors: true // Enable color-coding for debugging (VS Code does not currently emit colors, so none will be present there)
    },

    resolve: {
        // Add '.ts' and '.tsx' as resolvable extensions.
        extensions: [
            "",
            ".ico",
            ".js",
            ".ts",
            ".tsx",
            ".web.js",
            ".webpack.js"
        ]
    },

    module: {
        loaders: [
            // This loader copies the index.html file & favicon.ico to the output directory.
            {
                test: /\.(html|ico)$/,
                loader: 'file?name=[name].[ext]'
            },
            // All files with a '.ts' or '.tsx' extension will be handled by 'ts-loader'.
            {
                test: /\.tsx?$/,
                loaders: ["ts-loader"]
            }
        ],

        preLoaders: [
            // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
            {
                test: /\.js$/,
                loader: "source-map-loader"
            }
        ]
    },

    // When importing a module whose path matches one of the following, just
    // assume a corresponding global variable exists and use that instead.
    // This is important because it allows us to avoid bundling all of our
    // dependencies, which allows browsers to cache those libraries between builds.
    // externals: {
    //     "react": "React",
    //     "react-dom": "ReactDOM",
    //     "redux": "Redux"
    // }
};

推荐答案

output设置更改为name driven,例如.

    entry: {
        dash: 'app/dash.ts',
        home: 'app/home.ts',
    },
    output: {
        path: './public',
        filename: 'build/[name].js',
        sourceMapFilename: 'build/[name].js.map'
    },

Typescript相关问答推荐

对可变位置的父对象的TypScript空判断

为什么当我试图从数据库预填充时,属性x不存在于类型{错误:字符串; }.ts(2339)上?

如何获取数组所有可能的索引作为数字联合类型?

返回对象的TypScript构造函数隐式地替换This的值来替换super(.)的任何调用者?

创建一个通用上下文,允许正确推断其中的子项

APP_INITIALIZER—TypeError:appInits不是函数

在TypeScript中,除了映射类型之外还使用的`in`二进制运算符?

HttpClient中的文本响应类型选项使用什么编码?''

React typescribe Jest调用函数

创建一个根据布尔参数返回类型的异步函数

类型脚本基于数组作为泛型参数展开类型

适当限制泛型函数中的记录

如何在方法中正确地传递来自TypeScrip对象的字段子集?

将具有Readonly数组属性的对象接口转换为数组

为什么上下文类型在`fn|curred(Fn)`的联合中不起作用?

是否可以定义引用另一行中的类型参数的类型?

使用泛型以自引用方式静态键入记录的键

TypeScript中的这些条件类型映射方法之间有什么区别?

Typescript泛型验证指定了keyof的所有键

我可以在 Typescript 中重用函数声明吗?