vue.config.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 { FontsPlugin } = require('./web_plugins/fonts');
  8. const CopyPlugin = require('copy-webpack-plugin');
  9. const all_langs = require('./src/assets/langs.json');
  10. const langs = all_langs.filter((lang) => localConfig['availableLangs'].indexOf(lang.code) >= 0);
  11. const moment = require('moment');
  12. const today = moment().format('YYYY-MM-DDThh:mm:ss');
  13. const withoutLang = [
  14. { path: '/' },
  15. { path: '/colors' },
  16. { path: '/fonts' },
  17. { path: '/backgrounds' },
  18. { path: '/symbols' },
  19. { path: '/qrcode' },
  20. { path: '/edit' },
  21. ].concat(templatesRoutes.map((path) => ({ path: path })));
  22. let paths = [];
  23. paths = paths.concat(
  24. withoutLang.map((path) => {
  25. return { path: path.path };
  26. }),
  27. );
  28. for (const lang of langs) {
  29. paths = paths.concat(
  30. withoutLang.map((path) => {
  31. return { path: '/' + lang.code + path.path };
  32. }),
  33. );
  34. }
  35. const plugins = [
  36. new webpack.DefinePlugin({
  37. BUILD_UPDATE: JSON.stringify(today),
  38. }),
  39. new SitemapPlugin({
  40. base: localConfig.url,
  41. paths: paths,
  42. options: {
  43. filename: 'sitemap.xml',
  44. lastmod: true,
  45. },
  46. }),
  47. new FontsPlugin({
  48. fonts: require('./src/assets/local/data/fonts.json'),
  49. outputFile: 'static/fonts/fonts.css',
  50. aktivisda: require('./package.json').version,
  51. }),
  52. new CopyPlugin({
  53. patterns: [
  54. {
  55. from: './node_modules/@neslinesli93/mozjpeg-wasm/lib/mozjpeg-wasm.wasm',
  56. to: './js/mozjpeg_wasm.wasm',
  57. },
  58. {
  59. from: './node_modules/aktivisda-library/lib/compress/converters/oxipng/oxipng_bg.wasm',
  60. to: './js/oxipng.wasm',
  61. },
  62. ],
  63. options: {},
  64. }),
  65. ];
  66. module.exports = {
  67. publicPath: process.env.VUE_APP_NAME === 'aktivisda' ? '/' : '/backtivisda/',
  68. outputDir: `dist/${process.env.VUE_APP_NAME}`,
  69. chainWebpack: (config) => {
  70. config.plugin('html').tap((args) => {
  71. args[0].title = localConfig.name;
  72. return args;
  73. });
  74. if (process.env.VUE_APP_NAME === 'backtivisda') {
  75. config.plugin('copy').tap((options) => {
  76. options[0].patterns[0].globOptions.ignore.push('static/backgrounds/**/*');
  77. options[0].patterns[0].globOptions.ignore.push('static/symbols/**/*');
  78. options[0].patterns[0].globOptions.ignore.push('static/templates/**/*');
  79. return options;
  80. });
  81. }
  82. config.module
  83. .rule('vue')
  84. .use('vue-loader')
  85. .loader('vue-loader')
  86. .tap((options) => {
  87. options.hotReload = false;
  88. return options;
  89. });
  90. config.module
  91. .rule('svgz')
  92. .test(/\.svgz$/)
  93. .use('file-loader')
  94. .loader('file-loader')
  95. .options({ name: 'img/[name].[ext]' })
  96. .end();
  97. },
  98. configureWebpack: {
  99. plugins,
  100. resolve: {
  101. alias: {
  102. '@datastore': path.resolve('src', process.env.VUE_APP_NAME, 'datastore.js'),
  103. '@navbar': path.resolve('src', process.env.VUE_APP_NAME, 'components', 'navbar.vue'),
  104. },
  105. },
  106. },
  107. };