-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwebpack.config.prod.js
110 lines (100 loc) · 2.81 KB
/
webpack.config.prod.js
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* eslint-disable import/no-extraneous-dependencies, no-console */
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const webpack = require('webpack');
const fs = require('fs');
const css = require('./css.config');
function createEntries(base = '.', basename = '') {
const regularExpression = /\.jsx?$/;
const root = path.resolve(__dirname, base);
function readDirectory(directory, fileCache = {}) {
return fs.readdirSync(directory).reduce((files, file) => {
const fullPath = path.resolve(directory, file);
if (fs.statSync(fullPath).isDirectory()) {
return readDirectory(fullPath, files);
}
if (!regularExpression.test(fullPath)) return files;
const entryName = fullPath.replace(root, '').replace(regularExpression, '');
return Object.assign(files, { [`${basename}${entryName}`]: fullPath });
}, fileCache);
}
return readDirectory(root);
}
const componentEntries = createEntries('./src/components', 'components');
const decoratorEntries = createEntries('./src/decorators', 'decorators');
const externalEntries = createEntries('./src/external', 'external');
const iconEntries = createEntries('./src/icons', 'icons');
const entries = Object.assign(
{
dataUtils: './src/dataUtils.js',
},
componentEntries,
decoratorEntries,
externalEntries,
iconEntries
);
console.log('ENTRIES', entries);
module.exports = {
entry: Object.assign(
{
index: './src/index.js',
},
entries
),
externals: {
react: 'react',
'react-dom': 'react-dom',
lodash: 'lodash',
classnames: 'classnames',
},
output: {
path: path.resolve(__dirname, 'lib'),
filename: '[name].js',
library: '',
libraryTarget: 'commonjs2',
},
resolve: {
modules: [path.resolve('./node_modules')],
extensions: ['.js', '.jsx'],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
`css-loader?modules&importLoaders=1&localIdentName=${css.localIdentName}`,
'resolve-url-loader',
'sass-loader',
],
}),
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
`css-loader?importLoaders=1&localIdentName=${css.localIdentName}`,
'resolve-url-loader',
],
}),
},
{
test: /\.png$/,
loader: 'url-loader?limit=100000&mimetype=image/png',
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
new ExtractTextPlugin('styles.css'),
],
};