Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否在微信小程序编译时内置babel-plugin-dynamic-import-node #6955

Closed
superNos opened this issue Jul 7, 2020 · 2 comments
Closed
Labels
enhancement New feature or request

Comments

@superNos
Copy link

superNos commented Jul 7, 2020

编写跨端代码时,h5里有 import() 语法,编译成微信小程序时,代码报错,内置babel-plugin-dynamic-import-node在小程序端编译时,将import()转换为require,可以增加对import()语法的支持

@taro-bot2 taro-bot2 bot added the enhancement New feature or request label Jul 7, 2020
@superNos superNos changed the title 在微信小程序编译时内置babel-plugin-dynamic-import-node 能否在微信小程序编译时内置babel-plugin-dynamic-import-node Jul 10, 2020
@Chen-jj
Copy link
Contributor

Chen-jj commented Jul 13, 2020

@superNos 自己加一下咯,情况并没有太普遍,所以还是开发者自行添加吧。

Taro 3 操作 babel.config.js:

// babel-preset-taro 更多选项和默认值:
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md
const obj = {
  presets: [
    ['taro', {
      framework: 'react',
      ts: true
    }]
  ]
}

if (process.env.TARO_ENV === 'weapp') {
  obj.plugins = ["dynamic-import-node"]
}

module.exports = obj

Taro 2 操作 taro 的 babel 配置项。

@Chen-jj
Copy link
Contributor

Chen-jj commented Aug 3, 2020

v3.0.7+ 后内置支持

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants