Giter VIP home page Giter VIP logo

Comments (18)

justquanyin avatar justquanyin commented on May 13, 2024

引用了 babel-plugin-import , 以及使用了antd 的 Button组件, 未复现出问题,如方便,能贴出可复现的代码么? 或者加入钉钉群讨论一下

from beidou.

alex-my avatar alex-my commented on May 13, 2024

引用babel-plugin-import,需要什么配置嘛。
这里就是一个引入了antd的advanced 工程,然后看到警告,就添加了babel-plugin-import,但不知道如何在beidou中配置这个插件。

from beidou.

alex-my avatar alex-my commented on May 13, 2024

我写的代码在这里: https://github.com/alex-my/beidou-boilerplate
config/config.default.js 第25到28行是我的配置,但应该是没有配置正确,目前被我注释了。

from beidou.

njugray avatar njugray commented on May 13, 2024

@alex-my babel-plugin-import 是用来按需加载 antd 组件的 babel 插件,这部分功能主要用来减少js bundle的体积,对于node端意义不大。

isomorphic: {
    babel: {
      plugins: [
        [
          require.resolve('babel-plugin-import'),
          { libraryName: 'antd', libraryDirectory: 'es', style: 'css' },
        ],
      ],
    },
  },

这部分配置是对服务端生效的,你的目的应该想是在webpack打包中启用

如果想要启用 babel-plugin-import,可以这么写:

  1. 修改 config/config.default.js, 启用自定义webpack配置
webpack: {
    custom: {
      configPath: path.join(__dirname, './webpack.config.js'),
    },
  },
  1. 在 config/webpack.config.js 中修改babel-loader 配置,启用 .babelrc
module.exports = (app, defaultConfig /* , dev */) => {
  const babelLoader = defaultConfig.module.rules[0];

  babelLoader.use.options.babelrc = true;

  return defaultConfig;
};

defaultConfig的内容可以在 run/webpack.local.json 里查看 dump,babel-loader 是默认配置中的第一个 module.rule

  1. 在 .babelrc 中添加需要的配置
{
  "plugins": [["import", {
    "libraryName": "antd",
    "style": true
  }]]
}

from beidou.

ahungrynoob avatar ahungrynoob commented on May 13, 2024

兄弟,你热加载可以用吗,就是react的模块热替换。我一直报unaccepted module

from beidou.

alex-my avatar alex-my commented on May 13, 2024

目前需要手动刷新下页面,还没细看,今天周末我好好看看。

from beidou.

ahungrynoob avatar ahungrynoob commented on May 13, 2024

嗯嗯,我昨晚试了下可能是通用bug.我提个issue

from beidou.

njugray avatar njugray commented on May 13, 2024

@DXD23-SJTU simple示例
2018-08-11 11 09 44

from beidou.

alex-my avatar alex-my commented on May 13, 2024

@njugray 用以上方法尝试了下, 仍然会有警告

You are using a whole package of antd, please use https://www.npmjs.com/package/babel-plugin-import to reduce app bundle size.

.babelrc文件也生效了。代码见https://github.com/alex-my/beidou-boilerplate

from beidou.

njugray avatar njugray commented on May 13, 2024

@alex-my 上述方法是antd按需加载的配置方式,至于你这个告警我无法复现,如果实在node端上打印的话,没有影响的,node上引打包还是小包没大区别

from beidou.

alex-my avatar alex-my commented on May 13, 2024

这样子啊,我打包试试,谢谢。

from beidou.

ahungrynoob avatar ahungrynoob commented on May 13, 2024

@alex-my 有试着在生产环境下看看加载大小吗,我这边也是这个问题,然后试着生产环境跑了下,打包后的文件都找不到了。。。

from beidou.

ahungrynoob avatar ahungrynoob commented on May 13, 2024

我也发现没用,也没报错。。。打出来的index.js永远是2.2M无论我的组件是多还是少

from beidou.

njugray avatar njugray commented on May 13, 2024

@DXD23-SJTU
配置前:
image
配置后:
image

from beidou.

yangbo5207 avatar yangbo5207 commented on May 13, 2024

配置了babel import 同样没有生效,前后打包大小没变化 ~

from beidou.

justquanyin avatar justquanyin commented on May 13, 2024

你用的哪个例子? 或者把wepack的配置贴一下?

from beidou.

zhoufeii avatar zhoufeii commented on May 13, 2024

@alex-my babel-plugin-import 是用来按需加载 antd 组件的 babel 插件,这部分功能主要用来减少js bundle的体积,对于node端意义不大。

isomorphic: {
    babel: {
      plugins: [
        [
          require.resolve('babel-plugin-import'),
          { libraryName: 'antd', libraryDirectory: 'es', style: 'css' },
        ],
      ],
    },
  },

这部分配置是对服务端生效的,你的目的应该想是在webpack打包中启用

如果想要启用 babel-plugin-import,可以这么写:

  1. 修改 config/config.default.js, 启用自定义webpack配置
webpack: {
    custom: {
      configPath: path.join(__dirname, './webpack.config.js'),
    },
  },
  1. 在 config/webpack.config.js 中修改babel-loader 配置,启用 .babelrc
module.exports = (app, defaultConfig /* , dev */) => {
  const babelLoader = defaultConfig.module.rules[0];

  babelLoader.use.options.babelrc = true;

  return defaultConfig;
};

defaultConfig的内容可以在 run/webpack.local.json 里查看 dump,babel-loader 是默认配置中的第一个 module.rule

  1. 在 .babelrc 中添加需要的配置
{
  "plugins": [["import", {
    "libraryName": "antd",
    "style": true
  }]]
}

在启用之后再进行打包,虽然没有报错,但是也没有生效
image
image
image

@njugray

from beidou.

alex-my avatar alex-my commented on May 13, 2024

实际上antd按需加载是实现了的,可以用webpack-bundle-analyzer这个插件看看。

antd

实际上,无论是用babel-plugin-import还是手动引入,都这么大。
而真正大的是左侧的红框圈起来的。

from beidou.

Related Issues (20)

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.