【问题标题】:What's the difference between tsconfig's 'outFile' and webpack config's 'output'tsconfig 的 'outFile' 和 webpack config 的 'output' 有什么区别
【发布时间】:2017-11-26 12:56:59
【问题描述】:

“输出”路径有什么不同? tsconfig 是加载器吗?和 webpack 在运行 tsconfig 构建后解析“.ts”文件?
为什么找不到文件“src.js”?被webpack自动删除了?

tsconfig.json:

{
    "compilerOptions": {
        "module": "amd",
        "noImplicitAny": true,
        "removeComments": true,
        "preserveConstEnums": true,
        "outFile": "src.js",
        "sourceMap": true
    },
    "include": [
        "src/**/*"
    ],
    "exclude": [
        "node_modules"
    ]
}

webpack.config.js:

module.exports = {  
    entry: './index.ts',  
    output: {  
        filename: './dest.js'  
    },  
    module: {  
        loaders: [{  
            test: /\.ts$/,  
            loader:'ts-loader'
        }]  
    },  
    resolve: {  
        extensions: ['.webpack.js', '.web.js', '.ts', '.js']  
    }  
}  

当我运行 'webpack' 时,找不到 'src.js' 而 'dest.js' 没问题。

非常感谢。

【问题讨论】:

    标签: javascript typescript webpack ts-loader


    【解决方案1】:

    输出文件

    TS编译器在使用tsc命令时使用该配置选项

    连接并将输出发送到单个文件。

    您可以阅读有关编译器选项的更多信息here。

    输出

    这个配置选项被Webpack使用到

    顶级输出键包含指示 webpack 的一组选项 关于它应该如何以及在哪里输出你的包、资产和任何东西 否则你使用 webpack 打包或加载。

    为什么缺少 src.js

    当您使用 ts-loader 而不是 tsc 作为构建 webpack 的一部分时,不会使用来自 tsconfig.json 的 outFile 选项。 Webpack 在加载 .ts 文件时检测到应该将其传递给 ts-loader,而 ts-loader 反过来使用编译器编译仅此一个文件,然后将输出返回到 webpack。它永远不会像tsc 那样处理所有文件。这就是没有生成src.js 的原因。

    【讨论】:

    • 1:但是当我在 tsconfig.json 中删除 'outFile' 时,'dest.js' 没有我的任何代码,它们是 webpack 使用 amd generate 的默认代码。如果我添加 'outFile ','dest.js' 没问题。 2:当我删除 tsconfig.json 文件时,当我运行 'webpack' 时提示错误丢失此文件。
    • @FreeTears, _When I remove tsconfig.json file,it tips error missing this file when I run 'webpack'_ - ts-loader` 将此文件用于outFile 选项以外的许多事情,因此它是必需的。关于outFile的第一点没看懂,能详细点吗?
    猜你喜欢
    • 2021-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多