wildfirechat/vue-chat

import失败,提示export 'default' (imported as 'impl') was not found in '../proto/proto.min'

Closed this issue · 1 comments

imndx commented

原因是proto.min.jsbase64.min.js不需要通过babel转换,需要在babel的配置文件中将这两个文件忽略。

.babelrc参考配置如下:

{
 "presets": [
   ["env", {
     "modules": false,
     "targets": {
       "browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
     }
   }],
   "stage-2"
 ],
 "plugins": ["transform-vue-jsx", "transform-runtime"],
 "ignore": [
   "**/base64.min.js",
   "**/proto.min.js",
   "**/engine.min.js"
 ]
}

imndx commented

如果是create-react-app创建的react应用的话,默认没有开放配置,可以这么:

  1. 执行yarn eject或者npm run eject会在项目目录下生成config目录,该目录包含默认配置
  2. 修改config/webpack.config.js,在babel相关配置部分,加上上面的ignore配置,如下:

            // Process application JS with Babel.
            // The preset includes JSX, Flow, TypeScript, and some ESnext features.
            {
              test: /\.(js|mjs|jsx|ts|tsx)$/,
              include: paths.appSrc,
              loader: require.resolve('babel-loader'),
              options: {
                customize: require.resolve(
                  'babel-preset-react-app/webpack-overrides'
                ),
                presets: [
                  [
                    require.resolve('babel-preset-react-app'),
                    {
                      runtime: hasJsxRuntime ? 'automatic' : 'classic',
                    },
                  ],
                ],
                
                plugins: [
                  isEnvDevelopment &&
                    shouldUseReactRefresh &&
                    require.resolve('react-refresh/babel'),
                ].filter(Boolean),

                 // 下面 ignore 配置是新添加
                // ================================================================================
                 ignore: [
                   "**/base64.min.js",
                   "**/proto.min.js",
                   "**/engine.min.js"
                 ],
                // 上面 ignore 配置是新添加的
                // ===============================================================================

                // This is a feature of `babel-loader` for webpack (not Babel itself).
                // It enables caching results in ./node_modules/.cache/babel-loader/
                // directory for faster rebuilds.
                cacheDirectory: true,
                // See #6846 for context on why cacheCompression is disabled
                cacheCompression: false,
                compact: isEnvProduction,
              },
            },