Git Product home page Git Product logo

rax-app's People

Contributors

aladdin-add avatar andycall avatar answershuto avatar bakujun avatar balloonzzq avatar boiawang avatar chenjun1011 avatar chriscindy avatar clarkxia avatar dickeylth avatar doranyun avatar fengzilong avatar fyangstudio avatar giveme-a-name avatar icemic avatar imsobear avatar lianmin avatar luhc228 avatar orange-c avatar shiftj18 avatar solojiang avatar sylingd avatar wanglijie avatar wjq990112 avatar wssgcg1213 avatar xlianghang avatar yacheng avatar yinhangfeng avatar yuanyan avatar yuysmile avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rax-app's Issues

如何增加依赖检测

问题的背景:

package.json 里漏写了依赖,但是 CI 检测没有检测出来,是否有检测方法

为什么没有检测出来:

现在的依赖检测是基于 import/no-extraneous-dependencies 这条规则来做的

如果有如下的依赖引入:

import test from 'ava';

import/no-extraneous-dependencies 会分析本地是否能 resolve 到ava

  1. 如果能找到,但是 package.json 里没有声明依赖,那么就会出错误提示

  2. 但如果本地从未安装过 ava,那么就不会命中检测规则

在 CI 的场景,由于 package.json 里漏写了依赖,所以对应 2 的场景,检测规则不生效

社区类似讨论:import-js/eslint-plugin-import#1627

no-extraneous-dependencies 实现:https://github.com/benmosher/eslint-plugin-import/blob/master/src/rules/no-extraneous-dependencies.js

eslint-plugin-node 的检测规则 no-extraneous-require 和 eslint-plugin-import 的实现类似:都需要提前进行依赖安装

https://github.com/mysticatea/eslint-plugin-node/blob/master/lib/rules/no-extraneous-require.js#L45

其他解决方案

import/no-unresolved 可以检测资源路径是否能被 resolve 到,从而在 CI 场景下,检测出 package.json 中的依赖是否有缺失

但这条规则需要先执行 npm install 然后才能检测,在业务场景或 IDE 场景存在风险,不适合默认加到 rax 基础的 lint 规则里。

目前先对 raxrax-scripts, rax-components 这几个基础库单独加上该规则

Can't resolve 'react' in document.js when Compatibility with React

Module not found: Error: Can't resolve 'react' in '/Users/yuanyan/Rax/rax-demo3/src/document'

info WEBPACK Starting the development server at:
info     http://localhost:9999/

info WEBPACK Hash: 3213a9b0c471faa8e8ef
info WEBPACK Version: webpack 4.41.5
info WEBPACK Child
info WEBPACK     Hash: 3213a9b0c471faa8e8ef
info WEBPACK     Time: 14662ms
info WEBPACK     Built at: 2020-01-06 21:12:13
info WEBPACK                       Asset      Size            Chunks  Chunk Names
info WEBPACK                _document.js  17.3 KiB
info WEBPACK                web/index.js  2.32 MiB             index  index
info WEBPACK     web/pages_Home_index.js  43.7 KiB  pages_Home_index  pages_Home_index
info WEBPACK     Child
info WEBPACK                Asset      Size    Chunks  Chunk Names
info WEBPACK         _document.js  17.3 KiB  document  document
info WEBPACK
info WEBPACK         ERROR in ./src/document/index.jsx
info WEBPACK         Module not found: Error: Can't resolve 'react' in '/Users/yuanyan/Rax/rax-demo3/src/document'
info WEBPACK          @ ./src/document/index.jsx 1:0-38 7:5-18 9:5-18 9:32-45
info WEBPACK          @ multi ./src/document/index.jsx
info WEBPACK Compiled successfully
Set environment `DEBUG=true` to see detail error stacks.
html path is not found
import { createElement } from 'react';
import { Root, Style, Script} from 'rax-document';

function Document() {
  return (
    <html>
      <head>
        <meta charset="utf-8" />
        <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no,viewport-fit=cover"/>
        <title>rax-demo3</title>
        <Style />
      </head>
      <body>
        {/* root container */}
        <Root />
        <Script />
      </body>
    </html>
  );
}
export default Document;

babel-plugin-transform-jsx-stylesheet 存在性能问题

一个 Component 同时配置 className 与 style 字段时,会编译成如下:

<Component style={Object.assign({}, _styleSheet[className], style)} />

来自:
https://github.com/raxjs/rax-scripts/blob/c4565b0ef73d5a76aa77910952cb4e3f864aa487/packages/babel-plugin-transform-jsx-stylesheet/src/tests/index.js#L254-L269

这样会直接导致通过 memo 和 PureComponent 进行优化的 Component 优化无效。

react-perf/jsx-no-new-object-as-prop

是否可能将 className 与 style 的合并结果进行缓存,从而不影响 memo 和 PureComponent 的组件优化呢?

建议 document 渲染时取消默认添加 <!DOCTYPE html>

背景:

rax-app 使用 jsx 作为 document 的模板语言,目前构建产物最前面默认添加了
相关代码

        // get document html string
const pageSource = `<!DOCTYPE html>${renderToString(DocumentContextProviderElement)}`;

这样就对模板能力做了限制(和 ejs 能力不对等),比如我想渲染成非 html 就很麻烦。

建议:

  1. 取消默认添加
  2. rax-document 提供 DOCTYPE 组件(这个标签比较特别,非闭合)
  3. 目前如何写一个类似 DOCTYPE组件,也可以在文档里面描述一下,不然使用 jsx 作为模板语言,写起来有些痛苦

Rax 工程构建体积优化专项

背景

目前通过 externalrax-app 之后,体积能减少 50k。

Action

  • rax-apprax-pwa 替换为 create-app-container (缩减版 rax-pwa)
  • 在开发者没有使用到 tabBar 配置的时候,externalcreate-app-container
  • create-app-shared 中 env 相关的代码没有命中 platformLoader 的 AST 逻辑
  • 从 analyze 来看 tree-shaking 似乎没有生效需要进一步看看

[Feature]support @import '~file'; syntax in less

Is your feature request related to a problem? Please describe.
目前less文件中不支持 ~ 规则

@import '~/module/less/mixins.less';

这个语法, 常见的[style]-loader 有处理, 不过mp-loader会对样式文件进行预处理,还没有走到webpack的[style]-loader
Describe the solution you'd like
把mp-loader中对样式文件的处理逻辑拆出来,在webpack处理样式文件时进行处理

PHA 源码链路改动

  • app.json => manifest.json 原有链路有,部分细节需要改造
  • appWorker.js 增加 worker js
  • nsr 预渲染链路

[Feature]: rax-app support miniapp compile project

背景

rax-app 研发框架支持项目级编译时。

任务列表

  • 工程构建支持
  • 工程配置补齐
  • 运行时垫片适配
  • 运行时垫片扩充部分运行时能力 (优先级低)
  • 适配老工程
  • 文档补充

工程日志优化

  1. 默认工程会有如下报错

image

  1. 不同插件构建日志重复打印

rax-plugin-app 和 rax-plugin-multi-pages 在每次编译完后都会重复打印如下日志,只要保留一个就行了

image

  1. SSR 工程下 JSX+ 的日志重复打印

[Feature] 小程序工程能力抽离

背景

  • build-plugin-rax-app 逻辑过重,各个端的工程能力存在耦合关系,小程序 or Web 的工程能力需要频繁更新,现有模式不利于迭代维护
  • icejs 和 rax-app 同时需要使用小程序的工程能力,这部分代码逻辑较多,拆分出来之后更利于维护
  • 存在给飞猪提供 jsx2mp 这种特殊构建工具的包,每次小程序相关包 beta ,需要升级的链路较长,而且 jsx2mp 逻辑较重,不属于通用能力
  • 小程序工程能力,在组件/项目工程存在大量复用逻辑,并且目前组件工程不支持小程序运行时方案

方案

Step 1 (8月20日)

小程序工程能力抽离成 build-plugin-miniapp-compile/build-plugin-miniapp-runtimeexport default 出 build plugin 插件的同时,export 出工程配置的 API,从而便于现有项目向下兼容。

这两个插件将同时支持小程序项目工程的构建能力和组件工程的构建能力。

  • 接入现有 build-plugin-rax-app/build-plugin-rax-component,保证能力完全向下兼容
  • 接入 icejs

Step 2 (8月27日)

Web 等其他端的工程里梳理之后保留在原来 build-plugin-rax-app 中维护。

[Feature]: app plugin 中配置 devServer 的问题

表现

目前 build-plugin-rax-app 支持配置 devServer 字段,但是支持以下字段:
image
其中的字段名和 webpack-dev-server 是一致的,但是并不全,比如在 Web 场景中常见的存在跨域问题,需要设置其中的 proxy,用户需要单独写一个插件来做这件事

预期

既然已经有 devServer ,应该是和 webpack-dev-server 暴露出的所有字段一致?

document 支持 tsx

image

目前 typescript 脚手架里面的 document 文件还是 jsx,希望也可以支持 tsx

[Bug] rax-app 多页模式 mpa-loader 内联模式编译问题

背景

现有 MPA 的架构,会通过 webpack 内联 loader 的形式,给 entry 文件加上 mpa-loader(包裹自调用 render 逻辑)。这种处理方式存在的问题是,由于 entry loader (即内联 loader)的执行时机是晚于 normal loader 的,这就导致 babel 无法编译到通过内联 loader 添加的代码,导致在部分低端设备上出现代码未编译为 ES5 而报错的问题。

解决方案

MPA 的入口文件从 src/pages/Home/index 改为 .rax/pages/Home/Entry.tsx(以 Home 页面举例),在 Entry.tsx 里实现自调用 render 的逻辑,从而保证 loader 不会存在递归调用页面自身的问题。

递归调用页面自身: 如果只是将 mpa-loader 的类型改为 normal loader,会导致存在以下逻辑:

function mpaLoader() {
  return `import PageComponent from ${this.resoucePath}
 render(PageComponent);
`;
}

`build-plugin-rax-compat-react` not work with `antd-mobile`

Error message

(undefined) ./node_modules/antd-mobile/es/action-sheet/index.js
Module not found: Can't resolve 'react-dom' in '...'

Configuration (build.json)

{
  "plugins": [
    [
      "build-plugin-rax-app",
      {
        "targets": ["web", "wechat-miniprogram"]
      }
    ],
    "build-plugin-rax-compat-react"
  ]
}

TypeError: unknown: Cannot read property 'type' of undefined

at PluginPass.JSXOpeningElement (/Users/qindachang/Documents/Projects/go.heytea.com/node_modules/babel-plugin-transform-jsx-to-stylesheet/src/index/js:216:45)

if (hasStyleAttribute && styleAttribute.value) {
            let expression = styleAttribute.value.expression
            if(!expression) // 这里可能会出现undefined
              return
            let expressionType = expression.type

            // style={[styles.a, styles.b]} ArrayExpression
            if (expressionType === 'ArrayExpression') {
              expression.elements = arrayExpression.concat(expression.elements)
              // style={styles.a} MemberExpression
              // style={{ height: 100 }} ObjectExpression
              // style={{ ...custom }} ObjectExpression
              // style={custom} Identifier
              // style={getStyle()} CallExpression
              // style={this.props.useCustom ? custom : null} ConditionalExpression
              // style={custom || other} LogicalExpression
            } else {
              styleAttribute.value.expression = t.arrayExpression(arrayExpression.concat(expression))
            }
          } else {

调整 MPA 开启方式

问题: 目前 SPA 和 MPA 在开启方式上是不对等的,从 SPA 切换到 MPA 需要引入单独的插件,容易给用户造成理解成本

解决方案:将 MPA 的开启方式调整到 build-plugin-rax-app 内

{
  "plugins": [
    [
      "build-plugin-rax-app",
      {
        "targets": ["web"],
        "type": "mpa" // spa
      }
    ]
  ]
}

改动点:

  1. 抽取 MPA 相关配置到 rax-multi-page-config
  2. build-plugin-rax-app/build-plugin-rax-multi-pages 依赖 rax-multi-page-config 进行多页配置, 同时 set 多页标志到插件体系中
  3. 其他插件 ssr/def 去除对 build-plugin-rax-multi-pages 的直接判断,改为判断多页标志

feature: 初始化时候 支持跳过默认的选择

因为我是用了 自定义模板初始化项目。npm init rax demo --template xxxxxx
初始化的时候, 会让用户选择两个选项。问题在于 我自定义模板中 这两个问题是的答案写死的。
无论我这些 web 还是 miniapp 或是其他的选项。初始化出来的项目都与该两个选项无关。给用户造成误解。

image
image
所以期望能增加参数, 在初始化项目的时候跳过对默认选项的选择

[Docs] 升级指南补充

  • 工程配置迁移
  • 工程构建的差异性
  • 小程序原生代码放置的位置
  • public 文件夹的使用
  • 运行时能力的变化
  • 插件开发

build-plugin-rax-app 配置 hash 之后启动报错

TypeError: Cannot read property 'split' of undefined
    at Object.configWebpack (node_modules/build-plugin-rax-app/src/config/user/keys/hash.js:11:32)
    at node_modules/build-plugin-rax-app/src/config/ssr/getBase.js:33:20

build.json

{
  "plugins": [
    [
      "build-plugin-rax-app",
      {
        "targets": ["web"]
      }
    ]
  ],
  "hash": true
}

@alib/build-scripts: 0.1.12
build-plugin-rax-app: 2.0.0

[BUG]用 rax-scripts lineCSS 的方式打包 animate.css,在ios 上开启动画减弱的设备上会报错

出问题的代码:https://github.com/raxjs/rax-scripts/blob/083d98416234e1d031c6e405d01e1fc42ac8eb6f/packages/stylesheet-loader/src/index.js#L156

inlinceCSS 的模式打包 animate.css,_styles[key] 可能为空,导致 Object.assign 报错。

打包前:

@media print, (prefers-reduced-motion: reduce) {
  .animate__animated {
    -webkit-animation-duration: 1ms !important;
    animation-duration: 1ms !important;
    -webkit-transition-duration: 1ms !important;
    transition-duration: 1ms !important;
    -webkit-animation-iteration-count: 1 !important;
    animation-iteration-count: 1 !important;
  }

  .animate__animated[class*='Out'] {
    opacity: 0;
  }
}

打包后

var i = {
        animate__animated: {
          WebkitAnimationDuration: "1ms !important",
          animationDuration: "1ms !important",
          WebkitTransitionDuration: "1ms !important",
          transitionDuration: "1ms",
          WebkitAnimationIterationCount: "1 !important",
          animationIterationCount: "1 !important"
        }, 
        "animate__animated[class*='Out']": { opacity: 0 } // 这一条在 _styles 里不存在
};

要看下为啥这条样式在打包后丢失了。

以及为了保证健壮性,建议可以加上 为空判断 || {},来兼容不报错:

_styles[key] = Object.assign(_styles[key] || {}, ruleData[key]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.