vue.config.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. const webpack = require('webpack');
  2. const localConfig = require('./src/assets/local/localconfig.json');
  3. const templates = require('./src/assets/local/data/templates.json')['templates'];
  4. const templatesRoutes = templates.map((template) => `/edit/${template.id}`);
  5. const path = require('path');
  6. const SitemapPlugin = require('sitemap-webpack-plugin').default;
  7. const PrerenderSPAPlugin = require('prerender-spa-plugin');
  8. const { FontsPlugin } = require('./web_plugins/fonts');
  9. const CopyPlugin = require('copy-webpack-plugin');
  10. const Renderer = PrerenderSPAPlugin.PuppeteerRenderer;
  11. const all_langs = require('./src/assets/langs.json');
  12. const langs = all_langs.filter((lang) => localConfig['availableLangs'].indexOf(lang.code) >= 0);
  13. const moment = require('moment');
  14. const today = moment().format('YYYY-MM-DDThh:mm:ss');
  15. const withoutLang = [
  16. { path: '/' },
  17. { path: '/colors' },
  18. { path: '/fonts' },
  19. { path: '/backgrounds' },
  20. { path: '/symbols' },
  21. { path: '/qrcode' },
  22. { path: '/edit' },
  23. ].concat(templatesRoutes.map((path) => ({ path: path })));
  24. let paths = [];
  25. paths = paths.concat(
  26. withoutLang.map((path) => {
  27. return { path: path.path };
  28. }),
  29. );
  30. for (const lang of langs) {
  31. paths = paths.concat(
  32. withoutLang.map((path) => {
  33. return { path: '/' + lang.code + path.path };
  34. }),
  35. );
  36. }
  37. const plugins = [
  38. new webpack.DefinePlugin({
  39. BUILD_UPDATE: JSON.stringify(today),
  40. }),
  41. new SitemapPlugin({
  42. base: localConfig.url,
  43. paths: paths,
  44. options: {
  45. filename: 'sitemap.xml',
  46. lastmod: true,
  47. },
  48. }),
  49. new FontsPlugin({
  50. fonts: require('./src/assets/local/data/fonts.json'),
  51. outputFile: 'static/fonts/fonts.css',
  52. aktivisda: require('./package.json').version,
  53. }),
  54. new CopyPlugin({
  55. patterns: [
  56. {
  57. from: './node_modules/@neslinesli93/mozjpeg-wasm/lib/mozjpeg-wasm.wasm',
  58. to: './js/mozjpeg_wasm.wasm',
  59. },
  60. {
  61. from: './src/plugins/compress/converters/oxipng/oxipng_bg.wasm',
  62. to: './js/oxipng.wasm',
  63. },
  64. ],
  65. options: {},
  66. }),
  67. ];
  68. if (process.env.NODE_ENV === 'production') {
  69. plugins.push(
  70. new PrerenderSPAPlugin({
  71. staticDir: path.join(__dirname, 'dist', 'aktivisda'),
  72. registry: undefined,
  73. routes: paths.map((path) => path.path),
  74. renderer: new Renderer({
  75. onlyProduction: true,
  76. maxConcurrentRoutes: 8,
  77. renderAfterDocumentEvent: 'x-app-rendered',
  78. renderAfterTime: 50000,
  79. headless: true,
  80. injectProperty: '__prerender',
  81. // Optional - Any values you'd like your app to have access to via `window.injectProperty`.
  82. inject: {},
  83. }),
  84. minify: {
  85. collapseBooleanAttributes: true,
  86. collapseWhitespace: true,
  87. decodeEntities: true,
  88. keepClosingSlash: true,
  89. sortAttributes: true,
  90. },
  91. // // // TODO bug avec webpack 5 (voir https://www.npmjs.com/package/@dreysolano/prerender-spa-plugin)
  92. postProcess(renderedRoute) {
  93. // Ignore any repdirects.
  94. renderedRoute.route = renderedRoute.originalRoute;
  95. // Remove /index.html from the output path if the dir name ends with a .html file extension.
  96. // For example: /dist/dir/special.html/index.html -> /dist/dir/special.html
  97. if (renderedRoute.route.endsWith('.html')) {
  98. renderedRoute.outputPath = path.join(__dirname, 'dist', 'aktivisda', renderedRoute.route);
  99. } else {
  100. renderedRoute.outputPath = path.join(__dirname, 'dist', 'aktivisda', renderedRoute.route, 'index.html');
  101. }
  102. return renderedRoute;
  103. },
  104. }),
  105. );
  106. }
  107. module.exports = {
  108. publicPath: process.env.VUE_APP_NAME === 'aktivisda' ? '/' : '/backtivisda/',
  109. outputDir: `dist/${process.env.VUE_APP_NAME}`,
  110. chainWebpack: (config) => {
  111. config.plugin('html').tap((args) => {
  112. args[0].title = localConfig.name;
  113. return args;
  114. });
  115. if (process.env.VUE_APP_NAME === 'backtivisda') {
  116. config.plugin('copy').tap((options) => {
  117. options[0][0].ignore.push('static/backgrounds/**/*');
  118. options[0][0].ignore.push('static/symbols/**/*');
  119. options[0][0].ignore.push('static/templates/**/*');
  120. return options;
  121. });
  122. }
  123. config.module
  124. .rule('vue')
  125. .use('vue-loader')
  126. .loader('vue-loader')
  127. .tap((options) => {
  128. options.hotReload = false;
  129. return options;
  130. });
  131. config.module
  132. .rule('svgz')
  133. .test(/\.svgz$/)
  134. .use('file-loader')
  135. .loader('file-loader')
  136. .options({ name: 'img/[name].[ext]' })
  137. .end();
  138. },
  139. configureWebpack: {
  140. plugins,
  141. resolve: {
  142. alias: {
  143. '@datastore': path.resolve('src', process.env.VUE_APP_NAME, 'datastore.js'),
  144. '@navbar': path.resolve('src', process.env.VUE_APP_NAME, 'components', 'navbar.vue'),
  145. },
  146. },
  147. },
  148. };