vue.config.js 3.6 KB

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