如何将Typescript与React Native捆绑在一起

时间:2020-09-11 09:00:58

标签: reactjs typescript react-native webpack

我正在尝试为react-native创建一个库,现在我使用的是typescript和react-native-webview,但现在却使用webpack捆绑了。这是我的webpack配置

module.exports = {
    mode: 'production',
    entry: './src/index.ts',
    externals: {
        'react-native': true,
    },
    module: {
        rules: [
            {
                test: /\.(ts|tsx)?$/,
                include: path.resolve(__dirname, 'src'),
                use: [
                    {
                        loader: 'babel-loader',
                    },
                ]
            },
        ],
    },
    resolve: {
        extensions: [ '.tsx', '.ts', '.js' ],
    },
    output: {
        filename: 'index.js',
        path: path.resolve(__dirname, 'dist'),
        libraryTarget: 'umd',
        library: '',
    },
};

.babelrc

{
  "presets": [
    "@babel/preset-env",
    "module:metro-react-native-babel-preset"
  ]
}

运行webpack build

时出现此错误
ERROR in ./node_modules/react-native-webview/lib/WebView.js 7:36
Module parse failed: Unexpected token (7:36)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
| // implementation which is produced by Expo SDK 37.0.0.1 implementation, with
| // similar interface than the native ones have.
> var WebView = function () { return (<View style={{
|     alignSelf: 'flex-start',
|     borderColor: 'rgb(255, 0, 0)',

我哪里错了?请帮助我

0 个答案:

没有答案