From e9c844664065d0f1f443fd6ddf6f6434e7711e54 Mon Sep 17 00:00:00 2001 From: Robert Lange Date: Wed, 2 Oct 2019 08:55:38 +0200 Subject: [PATCH] fix: add dependecies to externals --- webpack-prod.config.js | 52 +++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/webpack-prod.config.js b/webpack-prod.config.js index 3bf2c2f..7954bb1 100644 --- a/webpack-prod.config.js +++ b/webpack-prod.config.js @@ -1,39 +1,53 @@ -var webpack = require('webpack'); -var path = require('path'); +const path = require('path'); +const pkg = require('./package.json'); -module.exports = { +const externals = new Set([ + ...Object.keys(pkg.dependencies || {}), + ...Object.keys(pkg.peerDependencies || {}), +]); + +const config = { entry: { - main: "./src/index.js", - Bootstrap: "./src/components/styled/Bootstrap.js", - Separate: "./src/components/separate/index.js", - AutocompleteField: "./src/components/AutocompleteField.jsx", - FormController: "./src/components/FormController.js" + main: './src/index.js', + Bootstrap: './src/components/styled/Bootstrap.js', + Separate: './src/components/separate/index.js', + AutocompleteField: './src/components/AutocompleteField.jsx', + FormController: './src/components/FormController.js', }, output: { path: path.join(__dirname, ''), - filename: "[name].js", - libraryTarget: "umd" + filename: '[name].js', + libraryTarget: 'umd', + }, + externals(context, request, callback) { + if (externals.has(request)) { + return callback(null, `${config.output.libraryTarget} ${request}`); + } + return callback(); }, resolve: { - extensions: ['.js', '.jsx'] + extensions: ['.js', '.jsx'], }, module: { loaders: [ { test: /\.css$/, - loader: 'style-loader!css-loader?modules=true&localIdentName=[name]__[local]___[hash:base64:5]' + loader: + 'style-loader!css-loader?modules=true&localIdentName=[name]__[local]___[hash:base64:5]', }, { test: /.jsx?$/, loader: 'babel-loader', exclude: /node_modules/, query: { - presets: ['es2015', 'stage-0', 'es2017', 'react'] - } - } - ] + presets: ['es2015', 'stage-0', 'es2017', 'react'], + }, + }, + ], }, devServer: { - historyApiFallback: true - } -}; \ No newline at end of file + historyApiFallback: true, + }, +}; + +module.exports = config;