robbie-sdk
Version:
Robbie Visio SDK to send events for analaysis
126 lines (115 loc) • 2.89 kB
JavaScript
; // eslint-disable-line
/**
* Webpack configuration base class
*/
const fs = require('fs');
const path = require('path');
const npmBase = path.join(__dirname, '../../node_modules');
const webpack = require('webpack');
class WebpackBaseConfig {
constructor() {
this._config = {};
this.gitCommit = require('child_process')
.execSync('git rev-parse --short HEAD')
.toString()
.replace(/\n|\r/g, '');
this.version = require('../../package.json').version
}
/**
* Get the list of included packages
* @return {Array} List of included packages
*/
get includedPackages() {
return [].map((pkg) => fs.realpathSync(path.join(npmBase, pkg)));
}
/**
* Set the config data.
* This will always return a new config
* @param {Object} data Keys to assign
* @return {Object}
*/
set config(data) {
this._config = Object.assign({}, this.defaultSettings, data);
this._config.plugins = this.defaultSettings.plugins.concat(data.plugins);
return this._config;
}
/**
* Get the global config
* @return {Object} config Final webpack config
*/
get config() {
return this._config;
}
/**
* Get the environment name
* @return {String} The current environment
*/
get env() {
return 'development';
}
/**
* Get the absolute path to src directory
* @return {String}
*/
get srcPathAbsolute() {
return path.resolve('./src');
}
/**
* Get the absolute path to tests directory
* @return {String}
*/
get testPathAbsolute() {
return path.resolve('./test');
}
/**
* Get the default settings
* @return {Object}
*/
get defaultSettings() {
return {
context: this.srcPathAbsolute,
entry: {
'robbie-visio-sdk': path.join(this.srcPathAbsolute, 'index.js')
},
devtool: 'source-map',
output: {
filename: '[name].js',
libraryTarget: 'var',
library: 'RobbieVisio',
path: path.join(this.srcPathAbsolute, '../build')
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
loader: 'eslint-loader',
exclude: [/node_modules/, /build/]
},
{
test: /\.js$/,
include: this.srcPathAbsolute,
loader: 'babel-loader',
query: {
presets: ['es2015']
}
},
{
test: /\.json$/,
loader: 'json-loader',
exclude: /node_modules/
}
]
},
plugins: [
new webpack.DefinePlugin({
GIT_HASH: JSON.stringify(this.gitCommit),
VERSION: JSON.stringify(this.version)
}),
new webpack.NamedModulesPlugin(),
new webpack.NoEmitOnErrorsPlugin()
],
};
}
}
module.exports = WebpackBaseConfig;