diff options
author | silverwind <me@silverwind.io> | 2020-05-14 18:06:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 19:06:01 +0300 |
commit | 9249c810b883406e649586f6731a820c1c96b698 (patch) | |
tree | 722e5645ed956858a757d0aba1db134df277c007 /webpack.config.js | |
parent | 984ee0113b50b21c8f5e570236e6dc1d32e1b6ba (diff) | |
download | gitea-9249c810b883406e649586f6731a820c1c96b698.tar.gz gitea-9249c810b883406e649586f6731a820c1c96b698.zip |
Switch code editor to Monaco (#11366)
* Switch code editor to Monaco
This switches out CodeMirror for Monaco which is based on the same code
base as VS code and should work pretty similar to it.
It does add a few async chunks, totalling around 10MB to our build. It
currently supports around 65 languages and in the default configuration,
each language would emit one ugly [number].js chunk, so I opted to
combine them all into a single file for now.
CodeMirror is still being used under the hood by SimpleMDE so it can not
be removed yet.
* inline editorconfig, fix diff, use for markdown, remove more dead code
* refactors, remove jquery usage
* use tab_width
* fix intellisense
* rename function for clarity
* misc tweaks, enable webpack progress display
* only use --progress on dev build
* remove useless borders in arc-green
* fix typo
* remove obsolete comment
* small refactor
* fix file creation and various refactors
* unset useTabStops too when no editorconfig
* small refactor
* disable webpack's [big] warnings
* remove useless await
* fix dark theme check
* rename chunk to 'monaco'
* add to .gitignore and delete webpack dest before build
* increase editor height
* support more editorconfig properties
* remove empty element filter
* rename
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Diffstat (limited to 'webpack.config.js')
-rw-r--r-- | webpack.config.js | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/webpack.config.js b/webpack.config.js index e87dd770cb..d6a632ad1f 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,6 +2,7 @@ const cssnano = require('cssnano'); const fastGlob = require('fast-glob'); const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); +const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin'); const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'); const PostCSSPresetEnv = require('postcss-preset-env'); const PostCSSSafeParser = require('postcss-safe-parser'); @@ -76,6 +77,14 @@ module.exports = { splitChunks: { chunks: 'async', name: (_, chunks) => chunks.map((item) => item.name).join('-'), + cacheGroups: { + // this bundles all monaco's languages into one file instead of emitting 1-65.js files + monaco: { + test: /monaco-editor/, + name: 'monaco', + chunks: 'async' + } + } } }, module: { @@ -91,6 +100,7 @@ module.exports = { }, { test: /\.worker\.js$/, + exclude: /monaco/, use: [ { loader: 'worker-loader', @@ -149,7 +159,10 @@ module.exports = { loader: 'css-loader', options: { importLoaders: 2, - url: false, + url: (_url, resourcePath) => { + // only resolve URLs for dependencies + return resourcePath.includes('node_modules'); + }, } }, { @@ -187,6 +200,19 @@ module.exports = { }, ], }, + { + test: /\.(ttf|woff2?)$/, + use: [ + { + loader: 'file-loader', + options: { + name: '[name].[ext]', + outputPath: 'fonts/', + publicPath: (url) => `../fonts/${url}`, // seems required for monaco's font + }, + }, + ], + }, ], }, plugins: [ @@ -209,9 +235,14 @@ module.exports = { new SpriteLoaderPlugin({ plainSprite: true, }), + new MonacoWebpackPlugin({ + filename: 'js/monaco-[name].worker.js', + }), ], performance: { hints: false, + maxEntrypointSize: Infinity, + maxAssetSize: Infinity, }, resolve: { symlinks: false, @@ -224,4 +255,7 @@ module.exports = { 'node_modules/**', ], }, + stats: { + children: false, + }, }; |