forked from motiondivision/motion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
116 lines (110 loc) · 2.93 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
const path = require('path');
const execSync = require('child_process').execSync;
const webpack = require('webpack');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const convertPathsToAliases = require('convert-tsconfig-paths-to-webpack-aliases')
.default;
const tsconfig = require('./tsconfig.json');
const BUILD_TYPE = process.env.BUILD_TYPE || 'debug';
const GIT_DESCRIBE = execSync('git describe --always --dirty')
.toString()
.trim();
const isProduction = BUILD_TYPE === 'production';
const tsLoader = {
loader: 'ts-loader',
options: { transpileOnly: true }
};
const config = {
mode: isProduction ? 'production' : 'development',
target: 'web',
entry: {
framer: [path.join(__dirname, './src/index')]
},
output: {
path: path.join(__dirname, 'build'),
filename: isProduction ? '[name].js' : '[name].debug.js',
library: 'Framer',
libraryTarget: 'umd'
},
devtool: isProduction ? 'source-map' : '#cheap-module-source-map',
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: [/__tests__/, /node_modules/],
use: isProduction ? [tsLoader] : ['cache-loader', tsLoader]
}
]
},
externals: {
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'ReactDOM',
commonjs: 'ReactDOM',
amd: 'ReactDOM'
}
},
resolve: {
modules: ['node_modules'],
extensions: ['.ts', '.tsx', '.js', '.json'],
alias: convertPathsToAliases(tsconfig)
},
performance: {
hints: false
},
plugins: [
new webpack.DefinePlugin({
'process.env.BUILD_NAME': JSON.stringify('framer'),
'process.env.BUILD_HASH': JSON.stringify(GIT_DESCRIBE),
'process.env.BUILD_TYPE': JSON.stringify(BUILD_TYPE),
'process.env.BUILD_DATE': JSON.stringify(new Date().toISOString()),
'process.env.NODE_ENV': JSON.stringify(BUILD_TYPE)
})
]
};
if (!isProduction) {
config.plugins.push(new ForkTsCheckerWebpackPlugin());
}
if (isProduction) {
config.devtool = 'source-map';
config.optimization = {
minimizer: [
new UglifyJSPlugin({
parallel: true,
sourceMap: true,
uglifyOptions: {
ecma: 6,
mangle: {
safari10: true,
keep_classnames: true
},
compress: {
warnings: false,
conditionals: true,
unused: true,
comparisons: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
keep_classnames: true
},
output: {
safari10: true,
beautify: false,
comments: false
}
}
})
]
};
}
module.exports = config;