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

browserslist设置无效 #452

Closed
chenyulun opened this issue Feb 14, 2022 · 5 comments
Closed

browserslist设置无效 #452

chenyulun opened this issue Feb 14, 2022 · 5 comments

Comments

@chenyulun
Copy link

father-build@1.21.1

然后再package.json里面配置

  "browserslist": [
    "chrome >= 90",
    "ios >= 15",
    "not IE 11"
  ]

然后代码里面写

const abc = async (params:string) => {
   console.log(params)
 }
 abc('111')

还是被降级了

import React from 'react';

/**
 * title: Foo demo
 * thumbnail: http://localhost:8080/#/calendar
 * previewUrl: http://localhost:8080/#/calendar
 */

var Foo = function Foo(_ref2) {
  var _ref2$title = _ref2.title,
      title = _ref2$title === void 0 ? '你好' : _ref2$title;
  return /*#__PURE__*/React.createElement("h1", null, title);
};

function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
  try {
    var info = gen[key](arg);
    var value = info.value;
  } catch (error) {
    reject(error);
    return;
  }

  if (info.done) {
    resolve(value);
  } else {
    Promise.resolve(value).then(_next, _throw);
  }
}

function _asyncToGenerator(fn) {
  return function () {
    var self = this,
        args = arguments;
    return new Promise(function (resolve, reject) {
      var gen = fn.apply(self, args);

      function _next(value) {
        asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
      }

      function _throw(err) {
        asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
      }

      _next(undefined);
    });
  };
}

var Button = function Button(_ref) {
  var _ref$type = _ref.type,
      type = _ref$type === void 0 ? 'primary' : _ref$type,
      _ref$children = _ref.children,
      children = _ref$children === void 0 ? null : _ref$children;

  var abc = /*#__PURE__*/function () {
    var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(params) {
      return regeneratorRuntime.wrap(function _callee$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              console.log(params);

            case 1:
            case "end":
              return _context.stop();
          }
        }
      }, _callee);
    }));

    return function abc(_x) {
      return _ref2.apply(this, arguments);
    };
  }();

  abc('111');
  return /*#__PURE__*/React.createElement("button", {
    type: "button",
    className: type
  }, children);
};

export { Button, Foo };
➜  dumitest npx browserslist
chrome 98
chrome 97
chrome 96
chrome 95
chrome 94
chrome 93
chrome 92
chrome 91
chrome 90
ios_saf 15.2-15.3
ios_saf 15.0-15.1
➜  dumitest 
@chenyulun
Copy link
Author

建议修改node_modules/father-build/src/getBabelConfig.ts配置,
建议1:去除写死配置babel会自动使用browserslist去查找当前执行目录的配置,不需要您这边写死
建议2:增加配置项,

  return {
    opts: {
      presets: [
        ...(typescript ? [require.resolve('@babel/preset-typescript')] : []),
        [require.resolve('@babel/preset-env'), {
-         targets,
          modules: type === 'esm' ? false : 'auto'
        }],
        ...(isBrowser ? [require.resolve('@babel/preset-react')] : []),
      ],

去掉就可以构建了

import React from 'react';

/**
 * title: Foo demo
 * thumbnail: http://localhost:8080/#/calendar
 * previewUrl: http://localhost:8080/#/calendar
 */

const Foo = _ref2 => {
  let {
    title = '你好'
  } = _ref2;
  return /*#__PURE__*/React.createElement("h1", null, title);
};

const Button = _ref => {
  let {
    type = 'primary',
    children = null
  } = _ref;

  const abc = async params => {
    console.log(params);
  };

  abc('111');
  return /*#__PURE__*/React.createElement("button", {
    type: "button",
    className: type
  }, children);
};

export { Button, Foo };

@PeachScript
Copy link
Member

目前 targets 不支持自定义,正在做 father 的下个大版本,新版会支持

@huarse
Copy link
Contributor

huarse commented Nov 23, 2022

目前 targets 不支持自定义,正在做 father 的下个大版本,新版会支持

所以现在 4.0 了,怎么自定义呢,文档上没有看到

@PeachScript
Copy link
Member

暂时还不支持

@PeachScript
Copy link
Member

感谢 @huarse 的 PR #549 ,targets 配置项已在 father 4 中支持:https://github.com/umijs/father/blob/master/docs/config.md#targets

issue 关闭

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

No branches or pull requests

3 participants