forked from nhn/tui.grid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
125 lines (120 loc) · 3.05 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
/* eslint-disable */
const path = require('path');
const package = require('./package');
const webpack = require('webpack');
const merge = require('webpack-merge');
const TerserPlugin = require('terser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const minify = process.argv.indexOf('--minify') >= 0;
const commonConfig = {
entry: './src/index.ts',
module: {
rules: [
{
test: /\.tsx?$/,
use: 'awesome-typescript-loader',
exclude: /node_modules/
}
]
},
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
output: {
library: ['tui', 'Grid'],
libraryTarget: 'umd',
filename: package.name + (minify ? '.min' : '') + '.js',
publicPath: '/',
path: path.resolve(__dirname, 'dist')
}
};
module.exports = (env, { mode = 'development' }) => {
if (mode === 'production') {
const { version, author, license } = package;
const banner = [
`TOAST UI Grid`,
`@version ${version} | ${new Date().toDateString()}`,
`@author ${author}`,
`@license ${license}`
].join('\n');
const productionConfig = {
mode,
plugins: [
new MiniCssExtractPlugin({
filename: package.name + (minify ? '.min' : '') + '.css'
}),
new webpack.BannerPlugin({ banner, entryOnly: true })
],
module: {
rules: [
{
test: /\.css$/,
exclude: /node_modules/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
}
]
},
externals: {
'tui-pagination': {
commonjs: 'tui-pagination',
commonjs2: 'tui-pagination',
amd: 'tui-pagination',
root: ['tui', 'Pagination']
},
'tui-date-picker': {
commonjs: 'tui-date-picker',
commonjs2: 'tui-date-picker',
amd: 'tui-date-picker',
root: ['tui', 'DatePicker']
}
},
optimization: {
minimize: false
}
};
if (minify) {
productionConfig.optimization = {
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
drop_console: true, // eslint-disable-line camelcase
warnings: true
},
output: {
comments: /TOAST UI Grid/i
}
}
}),
new OptimizeCSSAssetsPlugin({})
]
};
}
return merge(commonConfig, productionConfig);
}
return merge(commonConfig, {
mode,
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.css$/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }]
}
]
},
plugins: [
new HtmlWebpackPlugin({
filename: 'dist/index.html'
})
],
devServer: {
inline: true,
host: '0.0.0.0',
port: 8000,
disableHostCheck: true
}
});
};