Skip to content

Commit 71b86f7

Browse files
committed
env: build separated bundles for ie11
1 parent 37a208a commit 71b86f7

7 files changed

+91
-194
lines changed

apps/calendar/package.json

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@toast-ui/calendar",
33
"author": "NHN FE Development Lab <[email protected]>",
4-
"version": "2.0.0-dev",
4+
"version": "2.0.0-alpha",
55
"main": "dist/toastui-calendar.js",
66
"types": "types/index.d.ts",
77
"sideEffects": [
@@ -48,14 +48,13 @@
4848
"check-types": "tsc --project ./tsconfig.json --noEmit",
4949
"validate": "npm run check-types && npm run lint",
5050
"lint": "eslint .",
51-
"serve": "webpack serve --config webpack.dev.config.js",
5251
"cpy-dist2doc": "mkdir -p doc/dist && cp -f -r dist doc",
5352
"release-note": "tuie",
54-
"build": "rm -rf dist && npm run build:es5 && npm run build:es6 && npm run build:esm",
55-
"build:es5": "webpack && webpack --env minify",
56-
"build:es6": "webpack --config webpack.es6.config.js && webpack --config webpack.es6.config.js --env minify",
53+
"build:all": "rm -rf dist && npm run build && npm run build:ie11",
54+
"build": "webpack --config webpack.config.js && webpack --config webpack.config.js --env minify",
55+
"build:ie11": "webpack --config webpack.config.js --env ie11 && webpack --config webpack.config.js --env minify ie11",
5756
"build:esm": "tsc -p tsconfig.esm.json && prettier dist/esm/**/*.js --write",
58-
"analyze": "webpack --minify --profile --json > stats.json && webpack-bundle-analyzer stats.json ./dist",
57+
"analyze": "webpack --config webpack.config.js --env --profile --json > stats.json && webpack-bundle-analyzer stats.json ./dist",
5958
"storybook": "start-storybook -p 6006",
6059
"storybook:build": "build-storybook",
6160
"storybook:build:docs": "STORYBOOK_ENV=docs build-storybook",

apps/calendar/stats.json

+1
Large diffs are not rendered by default.

apps/calendar/webpack.common.config.js

-70
This file was deleted.

apps/calendar/webpack.config.js

+84-14
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,102 @@
11
/* 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');
27
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
38
const StyleLintPlugin = require('stylelint-webpack-plugin');
49
const ESLintPlugin = require('eslint-webpack-plugin');
510

611
const { merge } = require('webpack-merge');
7-
const common = require('./webpack.common.config');
812

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+
};
1289

1390
const config = {
1491
mode: 'production',
1592
entry: ['./src/css/index.css', './src/index.ts'],
1693
module: {
1794
rules: [
18-
// transpile libraries to es5
1995
{
2096
test: /\.(ts|tsx|js)$/,
2197
exclude: /node_modules/,
2298
loader: 'babel-loader',
23-
options: {
24-
rootMode: 'upward',
25-
},
99+
options: getBabelConfig(isIE11),
26100
},
27101
{
28102
test: /\.css$/,
@@ -43,12 +117,8 @@ module.exports = (env, argv) => {
43117
},
44118
],
45119
},
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` })],
51121
};
52122

53-
return merge(common(env, argv), config);
123+
return merge(commonConfig, config);
54124
};

apps/calendar/webpack.dev.config.js

-64
This file was deleted.

apps/calendar/webpack.es6.config.js

-31
This file was deleted.

babel.config.json

+1-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
{
22
"presets": [
3-
[
4-
"@babel/preset-env",
5-
{
6-
"useBuiltIns": "usage",
7-
"corejs": 3,
8-
"shippedProposals": true,
9-
"targets": "defaults"
10-
}
11-
],
3+
["@babel/preset-env"],
124
["@babel/preset-typescript", { "jsxPragma": "h" }]
135
],
146
"plugins": [["@babel/plugin-transform-react-jsx", { "pragma": "h", "pragmaFrag": "Fragment" }]]

0 commit comments

Comments
 (0)