Commit 54058266 authored by Nick Sellen's avatar Nick Sellen

Use raven with and without webpack environment

parent b27bdde1
import Raven from 'raven-js'
if (process.env.RAVEN_CONFIG) {
import serverData from '@/server-data'
if (serverData.ravenConfig) {
console.log('using raven config from server', serverData.ravenConfig)
Raven
.config(process.env.RAVEN_CONFIG)
.config(serverData.ravenConfig, { tags: { webpack: true } })
.install()
}
require('dotenv').config()
const webpack = require('webpack')
const { StatsWriterPlugin } = require('webpack-stats-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
......@@ -96,7 +93,7 @@ module.exports = {
filename: dev ? 'css/[name].css' : 'css/[id].[hash].css',
chunkFilename: 'css/[id].[hash].css'
}),
...(dev ? [new BundleAnalyzerPlugin({
new BundleAnalyzerPlugin({
analyzerMode: 'static',
reportFilename: 'bundlesize.html',
defaultSizes: 'gzip',
......@@ -105,12 +102,7 @@ module.exports = {
statsFilename: 'stats.json',
statsOptions: null,
logLevel: 'info'
})] : []),
new webpack.EnvironmentPlugin({
RAVEN_CONFIG: null
}),
// Writes modules.json which is then loaded by the php app (see src/Modules/Core/Control.php).
// This is how the php app will know if it is a webpack-enabled module or not.
new StatsWriterPlugin({
......
......@@ -37,6 +37,10 @@ if (defined('SENTRY_URL')) {
}
}
if (!defined('RAVEN_JAVASCRIPT_CONFIG') && getenv('RAVEN_JAVASCRIPT_CONFIG')) {
define('RAVEN_JAVASCRIPT_CONFIG', getenv('RAVEN_JAVASCRIPT_CONFIG'));
}
define('FPDF_FONTPATH', __DIR__ . '/lib/font/');
/* global definitions for Foodsharing\Lib\Func until they might
......
......@@ -1114,11 +1114,18 @@ Verantwortlich für den Inhalt nach § 55 Abs. 2 RStV:<br />
];
}
$ravenConfig = null;
if (defined('RAVEN_JAVASCRIPT_CONFIG')) {
$ravenConfig = RAVEN_JAVASCRIPT_CONFIG;
}
return array_merge($this->jsData, [
'webpack' => $usesWebpack,
'user' => $userData,
'page' => $this->getPage(),
'location' => $location
'location' => $location,
'ravenConfig' => $ravenConfig
]);
}
......@@ -1131,19 +1138,25 @@ Verantwortlich für den Inhalt nach § 55 Abs. 2 RStV:<br />
'css' => str_replace(["\r", "\n"], '', $this->add_css),
'jsFunc' => JSMin::minify($this->js_func),
'js' => JSMin::minify($this->js),
'serverDataJSON' => json_encode($this->getServerData($usesWebpack))
'serverDataJSON' => json_encode($this->getServerData($usesWebpack)),
'ravenConfig' => null
];
if ($usesWebpack) {
$data = array_merge($data, [
'stylesheets' => $this->webpackStylesheets,
'scripts' => $this->webpackScripts,
'scripts' => $this->webpackScripts
]);
} else {
$data = array_merge($data, [
'stylesheets' => $this->stylesheets,
'scripts' => $this->scripts,
'scripts' => $this->scripts
]);
if (defined('RAVEN_JAVASCRIPT_CONFIG')) {
$data['ravenConfig'] = RAVEN_JAVASCRIPT_CONFIG;
}
}
return $data;
......
......@@ -13,11 +13,17 @@
{% endfor %}
<script type="text/javascript">
window.serverData = {{ head.serverDataJSON | raw }};
window.serverData = {{ head.serverDataJSON | raw }};
</script>
{% if not head.webpack %}
{# the main webpack scripts are rendered at the bottom of the page #}
{# note: when using webpack the scripts are rendered at the bottom of the page #}
{% if head.ravenConfig %}
<script src="https://cdn.ravenjs.com/3.24.0/raven.min.js" crossorigin="anonymous"></script>
<script type="text/javascript">
Raven.config('{{ head.ravenConfig }}', { tags: { webpack: false } }).install()
</script>
{% endif %}
{% for script in head.scripts %}
<script type="text/javascript" src="{{ script }}"></script>
{% endfor %}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment