1
1
/* eslint @typescript-eslint/no-var-requires: "off" */
2
+ const pkg = require ( './package.json' ) ;
3
+ const path = require ( 'path' ) ;
4
+ const webpack = require ( 'webpack' ) ;
5
+ const TerserPlugin = require ( 'terser-webpack-plugin' ) ;
6
+ const CssMinimizerPlugin = require ( 'css-minimizer-webpack-plugin' ) ;
2
7
const MiniCssExtractPlugin = require ( 'mini-css-extract-plugin' ) ;
3
8
const StyleLintPlugin = require ( 'stylelint-webpack-plugin' ) ;
4
9
const ESLintPlugin = require ( 'eslint-webpack-plugin' ) ;
5
10
6
11
const { merge } = require ( 'webpack-merge' ) ;
7
- const common = require ( './webpack.common.config' ) ;
8
12
9
- module . exports = ( env , argv ) => {
10
- const { minify } = env ;
11
- const filename = `toastui-calendar${ minify ? '.min' : '' } .css` ;
13
+ function getBabelConfig ( isIE11 ) {
14
+ return {
15
+ presets : [
16
+ [
17
+ '@babel/preset-env' ,
18
+ {
19
+ useBuiltIns : 'usage' ,
20
+ corejs : '3.22' ,
21
+ targets : `defaults${ isIE11 ? '' : ', not ie 11' } ` ,
22
+ } ,
23
+ ] ,
24
+ [ '@babel/preset-typescript' , { jsxPragma : 'h' } ] ,
25
+ ] ,
26
+ plugins : [ [ '@babel/plugin-transform-react-jsx' , { pragma : 'h' , pragmaFrag : 'Fragment' } ] ] ,
27
+ } ;
28
+ }
29
+
30
+ module . exports = ( { minify, ie11 } ) => {
31
+ const shouldMinify = ! ! minify ;
32
+ const isIE11 = ! ! ie11 ;
33
+
34
+ const filenameBase = `toastui-calendar${ isIE11 ? '.ie11' : '' } ${ shouldMinify ? '.min' : '' } ` ;
35
+ const banner = [
36
+ 'TOAST UI Calendar 2nd Edition' ,
37
+ `@version ${ pkg . version } | ${ new Date ( ) . toDateString ( ) } ` ,
38
+ `@author ${ pkg . author } ` ,
39
+ `@license ${ pkg . license } ` ,
40
+ ] . join ( '\n' ) ;
41
+
42
+ const commonConfig = {
43
+ output : {
44
+ library : [ 'toastui' , 'Calendar' ] ,
45
+ libraryTarget : 'umd' ,
46
+ libraryExport : 'default' ,
47
+ path : path . join ( __dirname , 'dist' ) ,
48
+ filename : `${ filenameBase } .js` ,
49
+ publicPath : '/dist' ,
50
+ globalObject : 'this' ,
51
+ } ,
52
+ externals : {
53
+ 'tui-date-picker' : {
54
+ commonjs : 'tui-date-picker' ,
55
+ commonjs2 : 'tui-date-picker' ,
56
+ amd : 'tui-date-picker' ,
57
+ root : [ 'tui' , 'DatePicker' ] ,
58
+ } ,
59
+ 'tui-time-picker' : {
60
+ commonjs : 'tui-time-picker' ,
61
+ commonjs2 : 'tui-time-picker' ,
62
+ amd : 'tui-time-picker' ,
63
+ root : [ 'tui' , 'TimePicker' ] ,
64
+ } ,
65
+ } ,
66
+ resolve : {
67
+ extensions : [ '.ts' , '.tsx' , '.js' ] ,
68
+ alias : {
69
+ '@src' : path . resolve ( __dirname , './src/' ) ,
70
+ '@t' : path . resolve ( __dirname , 'types/' ) ,
71
+ } ,
72
+ } ,
73
+ plugins : [
74
+ new webpack . BannerPlugin ( {
75
+ banner,
76
+ entryOnly : true ,
77
+ } ) ,
78
+ new ESLintPlugin ( { extensions : [ '.tsx' , '.ts' , '.js' ] } ) ,
79
+ ] ,
80
+ optimization : shouldMinify
81
+ ? {
82
+ minimize : true ,
83
+ minimizer : [ new TerserPlugin ( { extractComments : false } ) , new CssMinimizerPlugin ( ) ] ,
84
+ }
85
+ : {
86
+ minimize : false ,
87
+ } ,
88
+ } ;
12
89
13
90
const config = {
14
91
mode : 'production' ,
15
92
entry : [ './src/css/index.css' , './src/index.ts' ] ,
16
93
module : {
17
94
rules : [
18
- // transpile libraries to es5
19
95
{
20
96
test : / \. ( t s | t s x | j s ) $ / ,
21
97
exclude : / n o d e _ m o d u l e s / ,
22
98
loader : 'babel-loader' ,
23
- options : {
24
- rootMode : 'upward' ,
25
- } ,
99
+ options : getBabelConfig ( isIE11 ) ,
26
100
} ,
27
101
{
28
102
test : / \. c s s $ / ,
@@ -43,12 +117,8 @@ module.exports = (env, argv) => {
43
117
} ,
44
118
] ,
45
119
} ,
46
- plugins : [
47
- new StyleLintPlugin ( ) ,
48
- new MiniCssExtractPlugin ( { filename } ) ,
49
- new ESLintPlugin ( { extensions : [ '.tsx' , '.ts' , '.js' ] } ) ,
50
- ] ,
120
+ plugins : [ new StyleLintPlugin ( ) , new MiniCssExtractPlugin ( { filename : `${ filenameBase } .css` } ) ] ,
51
121
} ;
52
122
53
- return merge ( common ( env , argv ) , config ) ;
123
+ return merge ( commonConfig , config ) ;
54
124
} ;
0 commit comments