在 create-react-app 中使用

    打开 访问你的应用。 先参考 入口页面 (html 或 模板) 相关设置,配置你的项目 html 页面。

    按需加载

    • 引入 并修改 package.json 里的启动配置。。由于新的 react-app-rewired@2.x 版本的关系,你需要还需要安装 。
    • 然后在项目根目录创建一个 config-overrides.js 用于修改默认配置。
    1. // do stuff with the webpack config...
    2. return config;
    3. };
    • 使用 babel-plugin-import, babel-plugin-import 是一个用于按需加载组件代码和样式的 babel 插件(),现在我们尝试安装它并修改 config-overrides.js 文件。
    1. + const { override, fixBabelImports } = require('customize-cra');
    2. - module.exports = function override(config, env) {
    3. - return config;
    4. - };
    5. + module.exports = override(
    6. + libraryName: 'antd-mobile',
    7. + style: 'css',
    8. + }),
    • 更改引用方式
    css-moulesantd-mobile-sample/create-react-app