Skip to content

Commit ac0a05e

Browse files
chippisoncaddoo
andauthored
Add the option to include source maps to served files (#23857)
* creating the script using environment variables * using value from configuration file. it looks cleaner * using matomo:console command instead * adding some comment * Adding some documentation in the README.md * adding help command * using short syntax * refactoring * fix spelling mistake * updating screenshot of configfile --------- Co-authored-by: caddoo <[email protected]>
1 parent ea9881d commit ac0a05e

File tree

5 files changed

+49
-6
lines changed

5 files changed

+49
-6
lines changed

.ddev/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ ddev matomo:init:dev
4444

4545
This command will set up the environment for development, installing the additional dependencies required.
4646

47+
We have also added a parameter to the `ddev matomo:init:dev` command to enable source maps for Vue components.
48+
To enable them, you can run:
49+
```
50+
ddev matomo:init:dev --with-sourcemaps
51+
```
52+
53+
You can also disable sourcemaps at any time if you want to, just run the default command again:
54+
```
55+
ddev matomo:init:dev
56+
```
57+
NOTE: You should tick 'Disable cache' on your browser developer tools to see the changes.
58+
59+
To see help:
60+
```
61+
ddev help matomo:init:dev
62+
```
63+
4764
### 4. Set up the testing environment
4865

4966
After Matomo is set up, you can initialize the testing environment by running:

.ddev/commands/host/matomo_init_dev

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
#!/usr/bin/env bash
22

33
## Description: Initialize Matomo environment for development
4-
## Usage: matomo:init:dev
5-
## Example: ddev matomo:init:dev
4+
## Usage: matomo:init:dev [--with-sourcemaps]
5+
## Example: ddev matomo:init:dev --with-sourcemaps
6+
7+
WITH_MAPS=0
8+
for arg in "$@"; do
9+
if [ "$arg" = "--with-sourcemaps" ]; then
10+
WITH_MAPS=1
11+
fi
12+
done
13+
14+
MAP_FLAG_VALUE=$([ "$WITH_MAPS" -eq 1 ] && echo 1 || echo 0)
15+
616

717
echo "Run npm install ..."
818
ddev npm install
@@ -11,6 +21,10 @@ echo "Enable development mode and disable assets merging ..."
1121
ddev matomo:console development:enable
1222
ddev matomo:console config:set Development.disable_merged_assets=1
1323

24+
echo "Configure Vue source maps"
25+
ddev matomo:console config:set Development.allow_vue_sourcemaps=$MAP_FLAG_VALUE
26+
## recreate the htaccess files to include/exclude maps
27+
ddev matomo:console core:create-security-files
28+
1429
echo "Done: Matomo dev setup initialisation finished."
1530
echo ""
16-

config/global.ini.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@
215215
; Note that for quick debugging, instead of using below setting, you can add `&disable_merged_assets=1` to the Matomo URL
216216
disable_merged_assets = 0
217217

218+
; if set to 1, the sourcemaps for built vue files will be allowed to be served.
219+
; this is useful for debugging vue files in the browser
220+
allow_vue_sourcemaps = 0
221+
218222
[General]
219223
; the following settings control whether Unique Visitors `nb_uniq_visitors` and Unique users `nb_users` will be processed for different period types.
220224
; year and range periods are disabled by default, to ensure optimal performance for high traffic Matomo instances

plugins/Installation/ServerFilesGenerator.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Piwik\Container\StaticContainer;
1313
use Piwik\Filesystem;
1414
use Piwik\SettingsServer;
15+
use Piwik\Config;
1516

1617
class ServerFilesGenerator
1718
{
@@ -37,6 +38,13 @@ public static function createHtAccessFiles()
3738
"\t" . $allow . "\n" .
3839
"</Files>\n";
3940

41+
$staticFileExtensions = ['gif', 'ico', 'jpg', 'png', 'svg', 'js', 'css', 'htm', 'html', 'mp3', 'mp4', 'wav', 'ogg', 'avi', 'ttf', 'eot', 'woff', 'woff2'];
42+
$allowVueSourceMaps = !empty(Config::getInstance()->Development['allow_vue_sourcemaps']);
43+
if ($allowVueSourceMaps) {
44+
$staticFileExtensions[] = 'map';
45+
}
46+
$staticFileExtensionsPattern = implode('|', $staticFileExtensions);
47+
4048
$allowStaticAssets =
4149
"# Serve HTML files as text/html mime type - Note: requires mod_mime apache module!\n" .
4250
"<IfModule mod_mime.c>\n" .
@@ -45,7 +53,7 @@ public static function createHtAccessFiles()
4553
"</IfModule>\n\n" .
4654

4755
"# Allow to serve static files which are safe\n" .
48-
"<Files ~ \"\\.(gif|ico|jpg|png|svg|js|css|htm|html|mp3|mp4|wav|ogg|avi|ttf|eot|woff|woff2)$\">\n" .
56+
"<Files ~ \"\\.(" . $staticFileExtensionsPattern . ")$\">\n" .
4957
$allow . "\n" .
5058
"</Files>\n";
5159

Lines changed: 2 additions & 2 deletions
Loading

0 commit comments

Comments
 (0)