const CopyPlugin = require('copy-webpack-plugin'); const webpack = require('webpack'); const fs = require('fs'); const path = require('path'); // Load developer-local overrides (gitignored) so `npm run build` picks up // TINODE_API_KEY etc. without having to export them by hand every time. const envLocalPath = path.resolve(__dirname, '.env.local'); if (fs.existsSync(envLocalPath)) { for (const line of fs.readFileSync(envLocalPath, 'utf8').split('\n')) { const match = line.match(/^\s*([A-Z_][A-Z0-9_]*)\s*=\s*(.*)\s*$/); if (match) { process.env[match[1]] = process.env[match[1]] || match[2]; } } } module.exports = (env, argv) => { const mode = argv.mode === 'production' ? 'prod' : 'dev'; const maxAssetSize = mode === 'prod' ? 360000 : 1512000; return { entry: { index: path.resolve(__dirname, 'src/index.js'), }, devtool: 'source-map', module: { rules: [ { test: /\.jsx?$/, use: [ { loader: 'babel-loader', options: { envName: mode === 'prod' ? 'production' : 'development', }, }, ], exclude: /node_modules/, }, ], }, output: { path: path.resolve(__dirname, 'umd'), filename: `[name].${mode}.js`, publicPath: '/umd/' }, optimization: { minimize: (mode === 'prod'), minimizer: ['...'] }, performance: { maxEntrypointSize: maxAssetSize, maxAssetSize: maxAssetSize, assetFilter: function(assetFilename) { // Exclude all sourcemaps if (/\.map$/.test(assetFilename)) { return false; } return true; }, }, plugins: [ new CopyPlugin({ patterns: [ { from: `node_modules/tinode-sdk/umd/tinode.${mode}.js`, to: `tinode.${mode}.js` }, { from: `node_modules/tinode-sdk/umd/tinode.${mode}.js.map`, to: `tinode.${mode}.js.map` }, ], }), // Bakes TINODE_API_KEY (from the environment or .env.local) into the bundle at build // time. See src/config.js for the fallback used when it's not set. new webpack.DefinePlugin({ 'process.env.TINODE_API_KEY': JSON.stringify(process.env.TINODE_API_KEY || ''), }), ], externals: { 'livekit-client': 'LivekitClient', 'qrcodejs': 'QRCode', 'react': 'React', 'react-dom': 'ReactDOM', 'react-intl': 'ReactIntl', 'tinode-sdk': 'tinode', }, }; }