从 Webpack 禁用捆绑 [英] Disable Bundling from Webpack

查看:36
本文介绍了从 Webpack 禁用捆绑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 webpack 用作打字稿构建工具,以便将每个打字稿文件翻译成 1 个 js 文件.

I want to use webpack just as a typescript build tool, such that each typescript file is translated into 1 js file.

webpack 指南有这样的配置:

The webpack guide has this configuration:

module.exports = {
    entry: './app.tsx',
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/
            }
        ]
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js']
    },
    output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist')
    }
};

问题:是否可以修改它,使

  • 每个 ts 文件转换为 1 个 js 文件和(更编译)
  • 这样就不会发生捆绑,也不会产生 module-webpack-boilerplate?

备注:

  1. 我知道我可以使用 tsc,但出于某些原因,如果可能的话,我想使用 webpack.我简化了我的场景.

  1. I know I can use tsc for that, but for some reasons I would like to use webpack if possible. I simplified my scenario.

还有一个问题听起来很相似,但那里的答案对我没有任何回答:如何在 Webpack 中禁用捆绑进行开发?

There is another question sounding like the very same but the answers there do not answer anything for me: How to disable bundling in Webpack for development?

推荐答案

我知道您想放弃捆绑并使用 Webpack 加载器.我自己已经考虑过这样做以加快我的开发构建过程.但是,我相信您链接的问题正确地陈述了答案:目前这是不可能的.最好的方法是使用 Webpack 配置中的 devtool 属性来启用源映射.如果您只想处理 TypeScript,另一种方法是使用 Gulp 或 Grunt 进行开发构建.

I understand you want to forego bundling and use the loaders with Webpack. I myself had considered this to speed up my dev build process. However, I believe the question you linked to states the answer correctly: this is not currently possible. The best approach is to use the devtool property in the Webpack config to enable sourcemaps. An alternative would be to use Gulp or Grunt for the dev build if all you want is to process TypeScript.

这篇关于从 Webpack 禁用捆绑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆