Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

webpack.config.js 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. import fastGlob from 'fast-glob';
  2. import wrapAnsi from 'wrap-ansi';
  3. import AddAssetPlugin from 'add-asset-webpack-plugin';
  4. import LicenseCheckerWebpackPlugin from 'license-checker-webpack-plugin';
  5. import MiniCssExtractPlugin from 'mini-css-extract-plugin';
  6. import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
  7. import {VueLoaderPlugin} from 'vue-loader';
  8. import EsBuildLoader from 'esbuild-loader';
  9. import {parse, dirname} from 'node:path';
  10. import webpack from 'webpack';
  11. import {fileURLToPath} from 'node:url';
  12. import {readFileSync} from 'node:fs';
  13. const {EsbuildPlugin} = EsBuildLoader;
  14. const {SourceMapDevToolPlugin, DefinePlugin} = webpack;
  15. const formatLicenseText = (licenseText) => wrapAnsi(licenseText || '', 80).trim();
  16. const glob = (pattern) => fastGlob.sync(pattern, {
  17. cwd: dirname(fileURLToPath(new URL(import.meta.url))),
  18. absolute: true,
  19. });
  20. const themes = {};
  21. for (const path of glob('web_src/css/themes/*.css')) {
  22. themes[parse(path).name] = [path];
  23. }
  24. const isProduction = process.env.NODE_ENV !== 'development';
  25. const filterCssImport = (url, ...args) => {
  26. const cssFile = args[1] || args[0]; // resourcePath is 2nd argument for url and 3rd for import
  27. const importedFile = url.replace(/[?#].+/, '').toLowerCase();
  28. if (cssFile.includes('fomantic')) {
  29. if (/brand-icons/.test(importedFile)) return false;
  30. if (/(eot|ttf|otf|woff|svg)$/.test(importedFile)) return false;
  31. }
  32. if (cssFile.includes('katex') && /(ttf|woff)$/.test(importedFile)) {
  33. return false;
  34. }
  35. if (cssFile.includes('font-awesome') && /(eot|ttf|otf|woff|svg)$/.test(importedFile)) {
  36. return false;
  37. }
  38. return true;
  39. };
  40. /** @type {import("webpack").Configuration} */
  41. export default {
  42. mode: isProduction ? 'production' : 'development',
  43. entry: {
  44. index: [
  45. fileURLToPath(new URL('web_src/js/jquery.js', import.meta.url)),
  46. fileURLToPath(new URL('web_src/fomantic/build/semantic.js', import.meta.url)),
  47. fileURLToPath(new URL('web_src/js/index.js', import.meta.url)),
  48. fileURLToPath(new URL('node_modules/easymde/dist/easymde.min.css', import.meta.url)),
  49. fileURLToPath(new URL('web_src/fomantic/build/semantic.css', import.meta.url)),
  50. fileURLToPath(new URL('web_src/css/index.css', import.meta.url)),
  51. ],
  52. webcomponents: [
  53. fileURLToPath(new URL('web_src/js/webcomponents/webcomponents.js', import.meta.url)),
  54. ],
  55. swagger: [
  56. fileURLToPath(new URL('web_src/js/standalone/swagger.js', import.meta.url)),
  57. fileURLToPath(new URL('web_src/css/standalone/swagger.css', import.meta.url)),
  58. ],
  59. serviceworker: [
  60. fileURLToPath(new URL('web_src/js/serviceworker.js', import.meta.url)),
  61. ],
  62. 'eventsource.sharedworker': [
  63. fileURLToPath(new URL('web_src/js/features/eventsource.sharedworker.js', import.meta.url)),
  64. ],
  65. ...themes,
  66. },
  67. devtool: false,
  68. output: {
  69. path: fileURLToPath(new URL('public', import.meta.url)),
  70. filename: ({chunk}) => {
  71. // serviceworker can only manage assets below it's script's directory so
  72. // we have to put it in / instead of /js/
  73. return chunk.name === 'serviceworker' ? '[name].js' : 'js/[name].js';
  74. },
  75. chunkFilename: ({chunk}) => {
  76. const language = (/monaco.*languages?_.+?_(.+?)_/.exec(chunk.id) || [])[1];
  77. return `js/${language ? `monaco-language-${language.toLowerCase()}` : `[name]`}.[contenthash:8].js`;
  78. },
  79. },
  80. optimization: {
  81. minimize: isProduction,
  82. minimizer: [
  83. new EsbuildPlugin({
  84. target: 'es2015',
  85. minify: true,
  86. css: true,
  87. legalComments: 'none',
  88. }),
  89. ],
  90. splitChunks: {
  91. chunks: 'async',
  92. name: (_, chunks) => chunks.map((item) => item.name).join('-'),
  93. },
  94. moduleIds: 'named',
  95. chunkIds: 'named',
  96. },
  97. module: {
  98. rules: [
  99. {
  100. test: /\.vue$/,
  101. exclude: /node_modules/,
  102. loader: 'vue-loader',
  103. },
  104. {
  105. test: /\.js$/,
  106. exclude: /node_modules/,
  107. use: [
  108. {
  109. loader: 'esbuild-loader',
  110. options: {
  111. loader: 'js',
  112. target: 'es2015',
  113. },
  114. },
  115. ],
  116. },
  117. {
  118. test: /\.css$/i,
  119. use: [
  120. {
  121. loader: MiniCssExtractPlugin.loader,
  122. },
  123. {
  124. loader: 'css-loader',
  125. options: {
  126. sourceMap: true,
  127. url: {filter: filterCssImport},
  128. import: {filter: filterCssImport},
  129. },
  130. },
  131. ],
  132. },
  133. {
  134. test: /\.svg$/,
  135. include: fileURLToPath(new URL('public/img/svg', import.meta.url)),
  136. type: 'asset/source',
  137. },
  138. {
  139. test: /\.(ttf|woff2?)$/,
  140. type: 'asset/resource',
  141. generator: {
  142. filename: 'fonts/[name].[contenthash:8][ext]',
  143. }
  144. },
  145. {
  146. test: /\.png$/i,
  147. type: 'asset/resource',
  148. generator: {
  149. filename: 'img/webpack/[name].[contenthash:8][ext]',
  150. }
  151. },
  152. ],
  153. },
  154. plugins: [
  155. new DefinePlugin({
  156. __VUE_OPTIONS_API__: true, // at the moment, many Vue components still use the Vue Options API
  157. __VUE_PROD_DEVTOOLS__: false, // do not enable devtools support in production
  158. }),
  159. new VueLoaderPlugin(),
  160. new MiniCssExtractPlugin({
  161. filename: 'css/[name].css',
  162. chunkFilename: 'css/[name].[contenthash:8].css',
  163. }),
  164. new SourceMapDevToolPlugin({
  165. filename: '[file].[contenthash:8].map',
  166. include: [
  167. 'js/index.js',
  168. 'css/index.css',
  169. ],
  170. }),
  171. new MonacoWebpackPlugin({
  172. filename: 'js/monaco-[name].[contenthash:8].worker.js',
  173. }),
  174. isProduction ? new LicenseCheckerWebpackPlugin({
  175. outputFilename: 'js/licenses.txt',
  176. outputWriter: ({dependencies}) => {
  177. const line = '-'.repeat(80);
  178. const goJson = readFileSync('assets/go-licenses.json', 'utf8');
  179. const goModules = JSON.parse(goJson).map(({name, licenseText}) => {
  180. return {name, body: formatLicenseText(licenseText)};
  181. });
  182. const jsModules = dependencies.map(({name, version, licenseName, licenseText}) => {
  183. return {name, version, licenseName, body: formatLicenseText(licenseText)};
  184. });
  185. const modules = [...goModules, ...jsModules].sort((a, b) => a.name.localeCompare(b.name));
  186. return modules.map(({name, version, licenseName, body}) => {
  187. const title = licenseName ? `${name}@${version} - ${licenseName}` : name;
  188. return `${line}\n${title}\n${line}\n${body}`;
  189. }).join('\n');
  190. },
  191. override: {
  192. 'jquery.are-you-sure@*': {licenseName: 'MIT'}, // https://github.com/codedance/jquery.AreYouSure/pull/147
  193. 'khroma@*': {licenseName: 'MIT'}, // https://github.com/fabiospampinato/khroma/pull/33
  194. },
  195. emitError: true,
  196. allow: '(Apache-2.0 OR BSD-2-Clause OR BSD-3-Clause OR MIT OR ISC OR CPAL-1.0 OR Unlicense OR EPL-1.0 OR EPL-2.0)',
  197. ignore: [
  198. 'font-awesome',
  199. ],
  200. }) : new AddAssetPlugin('js/licenses.txt', `Licenses are disabled during development`),
  201. ],
  202. performance: {
  203. hints: false,
  204. maxEntrypointSize: Infinity,
  205. maxAssetSize: Infinity,
  206. },
  207. resolve: {
  208. symlinks: false,
  209. },
  210. watchOptions: {
  211. ignored: [
  212. 'node_modules/**',
  213. ],
  214. },
  215. stats: {
  216. assetsSort: 'name',
  217. assetsSpace: Infinity,
  218. cached: false,
  219. cachedModules: false,
  220. children: false,
  221. chunkModules: false,
  222. chunkOrigins: false,
  223. chunksSort: 'name',
  224. colors: true,
  225. entrypoints: false,
  226. excludeAssets: [
  227. /^js\/monaco-language-.+\.js$/,
  228. !isProduction && /^js\/licenses.txt$/,
  229. ].filter(Boolean),
  230. groupAssetsByChunk: false,
  231. groupAssetsByEmitStatus: false,
  232. groupAssetsByInfo: false,
  233. groupModulesByAttributes: false,
  234. modules: false,
  235. reasons: false,
  236. runtimeModules: false,
  237. },
  238. };