Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
59 lines (49 loc) · 1.55 KB
/
Copy pathwebpack.config.js
File metadata and controls
59 lines (49 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const { readdirSync, lstatSync } = require('fs');
const { join } = require('path');
const webpack = require('webpack');
const Visualizer = require('webpack-visualizer-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const packagesDir = join(__dirname, './packages');
const isDirectory = source => lstatSync(join(packagesDir, source)).isDirectory();
const packages = readdirSync(packagesDir).filter(isDirectory);
const plugins = [
new Visualizer({ filename: '../bundle-stats.html' }),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
];
if (process.env.NODE_ENV === 'production') plugins.push(new UglifyJSPlugin({ sourceMap: true }));
module.exports = packages.map(packageName => ({
devtool: 'cheap-module-source-map',
entry: `${__dirname}/packages/${packageName}/src/index.js`,
resolve: {
mainFields: [
'jsnext:main',
'browser',
'main',
],
},
output: {
path: `${__dirname}/packages/${packageName}/umd`,
filename: `potion${packageName === 'main' ? '' : `-${packageName}`}${process.env.NODE_ENV === 'production' ? '.min' : ''}.js`,
library: `Potion${packageName === 'main' ? '' : `${packageName[0].toUpperCase()}${packageName.slice(1)}`}`,
libraryTarget: 'umd',
umdNamedDefine: true,
},
plugins,
externals: {
react: 'React',
'react-dom': 'ReactDOM',
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
},
},
],
},
}));