diff --git a/config/template.dev.json b/config/template.dev.json deleted file mode 100644 index 3505bf7..0000000 --- a/config/template.dev.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "apiHost": "https://dev.account.ely.by" -} diff --git a/config/template.env.js b/config/template.env.js new file mode 100644 index 0000000..53ff779 --- /dev/null +++ b/config/template.env.js @@ -0,0 +1,4 @@ +module.exports = { + apiHost: 'https://dev.account.ely.by', + ga: {id: 'UA-XXXXX-Y'} +}; diff --git a/src/index.ejs b/src/index.ejs index 47f8dc3..e66c4a6 100644 --- a/src/index.ejs +++ b/src/index.ejs @@ -22,5 +22,23 @@ <% for (var chunk in htmlWebpackPlugin.files.chunks) { %> <% } %> + +<% if (htmlWebpackPlugin.options.ga) { + if (!htmlWebpackPlugin.options.ga.id) { + throw new Error('ga.id is required to enable google analytics'); + } +%> + + + +<% } %> diff --git a/webpack.config.js b/webpack.config.js index a7b3723..ff0f235 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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) {