【问题标题】:Do not include vendor folder into webpack / Typescript不要将供应商文件夹包含在 webpack / Typescript 中
【发布时间】:2017-03-19 05:37:45
【问题描述】:

编辑:Typescript 通过 tsconfig.json 有自己的配置,我必须在那里添加供应商文件夹。

我的文件夹结构如下: misc/config/base.js misc/template.ejs sources/scripts/... sources/styles/... vendor/...

我的 webpack 配置看起来像:

    entry: [
        path.join(paths.scripts.path, paths.scripts.file),
        path.join(paths.styles.path, paths.styles.file),
    ],
    output: {
        path: paths.build.path,
        filename: paths.build.files.script,
        publicPath: '/',
    },
    resolve: {
        extensions: ['', '.webpack.js', '.web.js', '.ts', '.tsx', '.js', '.scss'],
    },
    module: {
        loaders: [
            {
                test: /\.(tsx|ts)$/,
                exclude: /node_modules/,
                // transformation order is from down to up
                loaders: [
                    'babel?'+JSON.stringify({
                        presets: ['es2015', 'react', 'stage-0'],
                        plugins: [babelRelayPlugin],
                    }),
                    'ts'],
            },
            {
                test: /\.scss$/,
                loader: ExtractTextPlugin.extract('style', ['css', 'postcss', 'sass']),
            },
            {
                test: /\.(woff|woff2|eot|ttf)$/,
                loader: 'url?limit=100000&name=./css/fonts/font-[hash].[ext]',
            },
            {
                test: /\.(png|svg)$/,
                loader: 'url?limit=100000&name=./img/[ext]/img-[hash].[ext]',
            },
        ],
    },

每次我启动 webpack 开发服务器时,它都会抱怨 ts 和 d.ts(打字稿文件),但实际上它根本不应该触及供应商。我怎样才能做到这一点?

编辑:我得到的几乎所有错误都是这样的: ERROR in /.../vendor/postgraphql/node_modules/typescript/lib/lib.es2015.iterable.d.ts (165,11): error TS2451: Cannot redeclare block-scoped variable 'String'.

【问题讨论】:

  • 据我了解,webpack 从入口点开始,解析每个 require 和 import 语句,并转译所有找到的文件。但是我的供应商文件夹在脚本或源文件夹中没有 require 调用。所以入口点不能链接到它。为什么要尝试 webpack 来做点什么?
  • 试试exclude: /(node_modules|vendor)/,
  • 不起作用。我猜 ts-loader 仍在检查 /.../vendor/postgraphql/node_modules/@types/node/index.d.ts (3040,10) 中的供应商文件夹错误:错误 TS2300:重复标识符 'HexBase64BinaryEncoding'。

标签: typescript webpack


【解决方案1】:

Typescript 通过 tsconfig.json 有自己的配置,我必须在那里添加供应商文件夹。

    "exclude": [
    "node_modules",
    "build",
    "vendor"
  ]
}

【讨论】:

    【解决方案2】:

    很可能是 babel 加载程序在这里抱怨试图解析您的供应商文件。如果是这种情况(很难确定没有看到错误),那么将加载器对象更改为此应该会有所帮助:

    {
        test: /\.(tsx|ts)$/,
        exclude: [/node_modules/, /vendor/],
        // transformation order is from down to up
        loaders: [
            'babel?'+JSON.stringify({
                presets: ['es2015', 'react', 'stage-0'],
                plugins: [babelRelayPlugin],
            }),
            'ts'],
    },
    

    【讨论】:

    • 不起作用。我猜 ts-loader 仍在检查 /.../vendor/postgraphql/node_modules/@types/node/index.d.ts (3040,10) 中的供应商文件夹错误:错误 TS2300:重复标识符 'HexBase64BinaryEncoding'。
    猜你喜欢
    • 1970-01-01
    • 2019-09-09
    • 2019-09-09
    • 1970-01-01
    • 1970-01-01
    • 2019-09-25
    • 1970-01-01
    • 2019-06-15
    • 1970-01-01
    相关资源
    最近更新 更多