/
webpack.config.js
100 lines (95 loc) · 2.22 KB
/
webpack.config.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
const _ = require('lodash');
const path = require('path');
const fs = require('fs');
const nodeExternals = require('webpack-node-externals');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const APP_PATH = path.join(__dirname, 'src');
const components = fs.readdirSync(path.join(APP_PATH, 'components'));
const entries = _.reduce(
components,
(acc, x) => {
if (!fs.statSync(`${path.join(APP_PATH, 'components')}/${x}`).isFile()) {
acc[`${x}/index`] = path.join(APP_PATH, `components/${x}/index.ts`);
}
return acc;
},
{}
);
const config = {
entry: Object.assign(
{},
{
index: path.join(APP_PATH, 'index.ts')
},
entries
),
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
library: '128-ui',
libraryTarget: 'umd',
umdNamedDefine: true
},
resolve: {
extensions: ['.jsx', '.js', '.ts', '.tsx'],
alias: {
react: path.resolve(__dirname, './node_modules/react'),
'react-dom': path.resolve(__dirname, './node_modules/react-dom'),
'@material-ui/core': path.resolve(__dirname, './node_modules/@material-ui/core')
}
},
module: {
rules: [
{
test: /\.(gif|png|jpg|svg|woff|ttf|eot|woff2)([?]?.*)$/,
use: [
{
loader: 'url-loader',
options: {
fallback: 'file-loader',
limit: 10000
}
}
]
},
{
test: /\.jsx?$/,
include: [APP_PATH],
use: ['babel-loader']
},
{
test: /\.tsx?$/,
exclude: [/node_modules/],
use: [
'babel-loader',
{
loader: 'ts-loader'
}
]
},
{
test: /\.*css$/,
use: [
'style-loader',
'css-loader',
'resolve-url-loader',
{
loader: 'sass-loader',
options: {
data: '@import "./src/styles/variables";',
sourceMap: true
}
}
]
}
]
},
externals: [nodeExternals()],
plugins: [new UglifyJsPlugin()]
};
module.exports = (env, argv = {}) => {
if (argv.mode === 'development') {
config.devtool = 'sourcemap';
}
return config;
};