不要将vendor文件夹包含在webpack / Typescript中

时间:2016-11-05 13:20:43

标签: typescript webpack

编辑: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 dev服务器时都会抱怨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'.

2 个答案:

答案 0 :(得分:2)

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

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

答案 1 :(得分:0)

很可能是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'],
},