-
Notifications
You must be signed in to change notification settings - Fork 56
/
webpack.config.js
135 lines (119 loc) · 3.16 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const path = require('path');
const webpack = require('webpack');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const createInnerJsxTransformer = require('typescript-plugin-inner-jsx').default;
const env = process.env.NODE_ENV || 'development';
const develop = env === 'development';
const test = env === 'test';
const production = env === 'production';
const port = process.env.PORT || 9000;
const dist = path.join(__dirname, 'dist', 'umd');
const src = path.join(__dirname, 'src');
const innerJsxTransformer = createInnerJsxTransformer();
function getEntrySources(sources = []) {
if (develop) {
sources.push(`webpack-dev-server/client?http://0.0.0.0:${port}`);
}
return sources;
}
function getFileName() {
const name = develop ? 'dev' : 'min';
return `precise-ui.${name}.js`;
}
function getExternals(libs = []) {
libs.push('react', 'react-dom', 'styled-components');
return libs;
}
module.exports = {
devtool: (develop || test) && 'source-map',
entry: {
main: getEntrySources([path.join(src, 'index.ts')]),
},
mode: production ? 'production' : 'development',
output: {
path: dist,
filename: getFileName(),
library: 'precise',
libraryTarget: 'umd',
publicPath: '/',
},
externals: getExternals(),
devServer: {
port,
historyApiFallback: true,
contentBase: dist,
hot: true,
inline: true,
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: {
'precise-ui': path.resolve('./src'),
},
},
module: {
rules: [
{
test: /node_modules[\/\\]((date-fns|ansi-styles|strip-ansi|ansi-regex|react-dev-utils|chalk|typescript-plugin-inner-jsx)[\/\\]).*/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
presets: [
[
'@babel/preset-env',
{
targets: {
ie: 11,
esmodules: true,
},
modules: 'commonjs',
},
],
'@babel/preset-typescript',
'@babel/preset-react',
],
plugins: [
['@babel/plugin-proposal-decorators', { legacy: true }],
['@babel/plugin-proposal-class-properties', { loose: true }],
'@babel/plugin-transform-runtime',
],
},
},
},
{
test: /\.tsx$/,
exclude: /node_modules/,
loader: 'ts-loader',
options: {
getCustomTransformers: () => ({ before: [innerJsxTransformer] }),
},
},
{
test: /\.ts$/,
exclude: /node_modules/,
loader: 'ts-loader',
options: {
silent: true
}
},
{
enforce: 'pre',
exclude: /node_modules/,
test: /\.js$/,
loader: 'source-map-loader',
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(env),
}),
new CircularDependencyPlugin({
exclude: /node_modules/,
failOnError: true,
allowAsyncCycles: false,
cwd: process.cwd(),
}),
],
};