s-panferov / awesome-typescript-loader

Awesome TypeScript loader for webpack
Other
2.35k stars 179 forks source link

Work with babel plugin #556

Open lijialiang opened 6 years ago

lijialiang commented 6 years ago

package.json

"devDependencies": {
    "@babel/core": "^7.0.0-beta.42",
    "@babel/plugin-proposal-optional-chaining": "^7.0.0-beta.42",
    "awesome-typescript-loader": "^4.0.1",
    "webpack": "^4.2.0",
    "webpack-cli": "^2.0.13",
    "babel-loader": "^8.0.0-beta.2",
    "typescript": "^2.7.2"
}

webpack.config.js

module.exports = {
    mode: 'production',
    entry: [
        './index-1.js', './index-2.ts',
    ],
    output: {
        filename: '[name].tt.js',
    },
    module: {
        rules: [
            {
                test: /\.*(js|jsx)$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'babel-loader',
                        options: {
                            presets: [ ],
                            plugins: [
                                '@babel/plugin-proposal-optional-chaining',
                            ],
                        }
                    },
                ]
            },
            {
                test: /\.*(ts|tsx)$/,
                exclude: /node_modules/,
                use: [
                    {
                        loader: 'awesome-typescript-loader',
                        options: {
                            silent: true,
                            configFileName: './tsconfig.json',
                            useBabel: true,
                            babelCore: '@babel/core',
                            babelOptions: {
                                babelrc: false,
                                presets: [ ],
                                plugins: [
                                    '@babel/plugin-proposal-optional-chaining',
                                ],
                            },
                        },
                    }
                ]
            },
        ]
    }
};

index-1.js & index-2.ts

console.log( window.test?.( ) );

Problem

the js file can be compiled, the ts file has error.


ERROR in ./index-2.ts
Module build failed: SyntaxError: index-2.ts: Unexpected token (1:26)

> 1 | console.log(window.test ? .() : );
``
Nazar32 commented 6 years ago

Having the same issue. Did you resolve it?

lijialiang commented 6 years ago

@Nazar32 sorry, I have not found a suitable solution yet :(