mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-30 02:32:58 +05:30
#207: add ga support
This commit is contained in:
parent
666f5f218a
commit
3d98747c42
@ -1,3 +0,0 @@
|
||||
{
|
||||
"apiHost": "https://dev.account.ely.by"
|
||||
}
|
4
config/template.env.js
Normal file
4
config/template.env.js
Normal file
@ -0,0 +1,4 @@
|
||||
module.exports = {
|
||||
apiHost: 'https://dev.account.ely.by',
|
||||
ga: {id: 'UA-XXXXX-Y'}
|
||||
};
|
@ -22,5 +22,23 @@
|
||||
<% for (var chunk in htmlWebpackPlugin.files.chunks) { %>
|
||||
<script src="<%= htmlWebpackPlugin.files.chunks[chunk].entry %>"></script>
|
||||
<% } %>
|
||||
|
||||
<% if (htmlWebpackPlugin.options.ga) {
|
||||
if (!htmlWebpackPlugin.options.ga.id) {
|
||||
throw new Error('ga.id is required to enable google analytics');
|
||||
}
|
||||
%>
|
||||
<!-- Google Analytics -->
|
||||
<script>
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||
|
||||
ga('create', '<%- htmlWebpackPlugin.options.ga.id %>', 'auto');
|
||||
ga('send', 'pageview');
|
||||
</script>
|
||||
<!-- End Google Analytics -->
|
||||
<% } %>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -13,6 +13,13 @@ const vendor = Object.keys(require('./package.json').dependencies);
|
||||
|
||||
const rootPath = path.resolve('./src');
|
||||
|
||||
var config = {};
|
||||
try {
|
||||
config = require('./config/env.js');
|
||||
} catch (err) {
|
||||
console.error('\n\n===\nCan not find config/env.js. Running with defaults\n===\n\n', err);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: https://babeljs.io/docs/plugins/
|
||||
* TODO: отдельные конфиги для env (аля https://github.com/davezuko/react-redux-starter-kit)
|
||||
@ -110,7 +117,8 @@ var webpackConfig = {
|
||||
inject: false,
|
||||
minify: {
|
||||
collapseWhitespace: isProduction
|
||||
}
|
||||
},
|
||||
ga: config.ga
|
||||
}),
|
||||
new webpack.ProvidePlugin({
|
||||
// window.fetch polyfill
|
||||
@ -237,32 +245,26 @@ if (isProduction) {
|
||||
}
|
||||
|
||||
if (!isProduction && !isTest) {
|
||||
var config;
|
||||
try {
|
||||
config = require('./config/dev.json');
|
||||
} catch (err) {
|
||||
console.error('\n\n===\nPlease create dev.json config under ./config based on template.dev.json\n===\n\n');
|
||||
throw err;
|
||||
}
|
||||
|
||||
webpackConfig.plugins.push(
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
new webpack.NoErrorsPlugin()
|
||||
);
|
||||
|
||||
webpackConfig.devServer = {
|
||||
host: 'localhost',
|
||||
port: 8080,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: config.apiHost,
|
||||
changeOrigin: true // add host http-header, based on target
|
||||
}
|
||||
},
|
||||
hot: true,
|
||||
inline: true,
|
||||
historyApiFallback: true
|
||||
};
|
||||
if (config.apiHost) {
|
||||
webpackConfig.devServer = {
|
||||
host: 'localhost',
|
||||
port: 8080,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: config.apiHost,
|
||||
changeOrigin: true // add host http-header, based on target
|
||||
}
|
||||
},
|
||||
hot: true,
|
||||
inline: true,
|
||||
historyApiFallback: true
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
if (isDockerized) {
|
||||
|
Loading…
Reference in New Issue
Block a user