UNPKG

rocketfuel-node-sdk

Version:

JS SDK for RocketFuel Payment Method

124 lines (114 loc) 2.28 kB
const path = require('path'); const HTMLWebpackPlugin = require('html-webpack-plugin'); // const webpack = require('webpack'); const isDev = process.env.NODE_ENV === 'development'; const isProd = !isDev; const jsLoaders = () => { const loaders = [ { loader: 'babel-loader', options: { presets: [ '@babel/preset-env' ], plugins: [ '@babel/plugin-proposal-class-properties' ] } } ] if (isDev) { loaders.push('eslint-loader'); } return loaders; } const entryFile = () => { const entry = { 'rocketfuel-node-sdk': ['@babel/polyfill', './index.js'], } if (isDev) { entry.test = './test/main.js' } return entry; } const plugins = () => { const plugins = []; if (isDev) { plugins.push( new HTMLWebpackPlugin({ filename: 'index.html', template: './test/index.html', }), ); } return plugins; } const clientConfig = { context: path.resolve(__dirname, 'src'), entry: entryFile(), output: { filename: `[name].js`, path: path.resolve(__dirname, 'dist'), library: 'RocketfuelJs', libraryTarget:'umd', umdNamedDefine: true, globalObject: `(typeof self !== 'undefined' ? self : this)` }, resolve: { modules: [ 'node_modules' ], extensions: ['.js', '.json'], }, plugins: plugins(), devServer: { port: 9090, hot: isDev, host: 'localhost' }, module: { rules: [ { test: /\.js$/, use: jsLoaders() } ] }, } const serverConfig = { target: 'node', context: path.resolve(__dirname, 'src'), entry: { 'rocketfuel-sdk-node': ['@babel/polyfill', './index.js'], }, output: { filename: `[name].js`, path: path.resolve(__dirname, 'dist'), library: 'RocketfuelJS', libraryTarget:'umd', umdNamedDefine: true, globalObject: `(typeof self !== 'undefined' ? self : this)` }, resolve: { modules: [ 'node_modules' ], extensions: ['.js', '.json'], }, module: { rules: [ { test: /\.js$/, use: jsLoaders() } ] }, node: { fs: 'empty' } } const configs = [clientConfig]; if (isProd) { configs.push(serverConfig); } module.exports = configs;