create-react-app andt 打包的 js 文件过大

2019-03-07 08:15:41 +08:00
 kingofvir

初步学习 react 使用 antd 官方的配置好按需加载之后,发现 npm run start 和 npm run buidl 之后的 static/js/0.chunk.js 文件有 3.5+M,

使用的是官方 config-overrides.js:

const {override, fixBabelImports, addLessLoader} = require('customize-cra');

module.exports = {
    webpack: override(
        fixBabelImports('import', {
            libraryName: 'antd',
            libraryDirectory: 'es',
            style: true,
        }),

        addLessLoader({
            javascriptEnabled: true,
            // modifyVars: {'@primary-color': '#1DA57A'},
        }),
    )
};

static/js/0.chunk.js 大多是:

"./node_modules/react-redux/es/components/Provider.js": 
"./node_modules/react-router-dom/es/matchPath.js": 
"./node_modules/resize-observer-polyfill/dist/ResizeObserver.es.js":
      

这些,这些在 demo 中是有用到的 但是打成 3.5+M 这么大我是不太理解。我是后段学习 react,关于 webpack 打包方面不太很深入的了解,请各位指导下。

3928 次点击
所在节点    React
1 条回复
dcatfly
2019-03-07 09:56:09 +08:00
应该是没开生产环境模式,可能没有压缩并且有 sourcemap。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/541949

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX