Closed kyeotic closed 3 years ago
I might be reading this incorrectly, but it looks like you hardcode the loading of all languages from prism. It would be nice to be able to pair this down, perhaps by using the prism webpack plugin in the client app and defining the languages as props.
@kyeotic These small JS files are loaded when used, and do not affect the size of the packaged JS.
My application scenario cannot determine which languages to load.
@jaywcjlove Yes, but the bundles are still present in the deployment, and they still add considerable noise to the build and source-map-explorer report. It would be nice if we could whitelist languages so that applications that did know which languages it supported could keep the rest from being bundled. This would be valuable even if the default was to bundle them all.
@kyeotic This requires writing a webpack plugin. This needs to be studied.
@kyeotic We need a plugin like monaco-editor-webpack-plugin
I'm actually having a lot of trouble getting the prism webpack plugin to do anything. I tried forking this repo and trimming down the languages, then built with the prism plugin on the lib. I even added the plugin to the app that installed the editor, so that it was running in both places. I get 370+ bundles, which is smaller but not by half as many languages as I removed.
@kyeotic thx! this good idea. I will deal with it when I have time. @uiwjs/react-markdown-preview
is there any possible solution without ejecting create-react-app?
@ppascualv https://github.com/kktjs/kkt Override create-react-app webpack configs without ejecting
Is there any solution for this issue or any workaround without ejecting the app? I was taking a look at your library but I'm not sure how can it solve the issue.
@ppascualv Add webpack config.
@ppascualv Dynamic import is used. Unable to split chunks it.
https://v4.webpack.js.org/plugins/split-chunks-plugin/#split-chunks-example-1
This configuration can enlarge your initial bundles, it is recommended to use dynamic imports when a module is not immediately needed.
it's not work
webpack.config.js
optimization: {
// Automatically split vendor and commons
// https://twitter.com/wSokra/status/969633336732905474
// https://medium.com/webpack/webpack-4-code-splitting-chunk-graph-and-the-splitchunks-optimization-be739a861366
splitChunks: {
// chunks: 'all',
// name: false,
cacheGroups: {
markdown_editor: {
test: /[\\/]node_modules[\\/]@uiw[\\/]/,
name: 'vendors-markdown',
chunks: 'all',
}
}
},
}
how to use it
@guoseven Modify webpack configuration. https://webpack.js.org/configuration/optimization/#optimizationsplitchunks
When bundled with create-react-app default settings this library produces over 400 chunked bundles. They are invidually all small, but total almost 1mb. I don't know what they all are, and they don't all appear to be loaded, but it is quite strange.
It looks like they are mostly from prism. I'm guessing they are individual language highlighting packs. Perhaps there is a way to skip them?
This tool is beautiful by the way, thank you for making it. This is easily the nicest markdown editor I've come across