Skip to content

Commit

Permalink
chore: set webpack optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
heenakwag committed Dec 12, 2019
1 parent 8caed42 commit 0e3410a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ tui.date-picker/
├─ latest
│ ├─ tui-date-picker.css
│ ├─ tui-date-picker.js
│ ├─ tui-date-picker.min.js
├─ v3.0.0/
│ ├─ tui-date-picker.min.css
│ └─ tui-date-picker.min.js
├─ v4.0.0/
│ ├─ ...
```

Expand Down
32 changes: 28 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,33 @@ var path = require('path');
var pkg = require('./package.json');
var webpack = require('webpack');
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
var TerserPlugin = require('terser-webpack-plugin');
var OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');

function setOptimization(isMinified) {
if (isMinified) {
return {
minimizer: [
new TerserPlugin({
cache: true,
parallel: true,
sourceMap: false,
extractComments: false
}),
new OptimizeCSSAssetsPlugin()
]
};
}

return {
minimize: false
};
}

module.exports = function(env, argv) {
var isProduction = argv.mode === 'production';
var FILENAME = pkg.name + (isProduction ? '.min.js' : '.js');
var isMinified = !!argv.minify;
var FILENAME = pkg.name + (isMinified ? '.min' : '');
var BANNER = [
'TOAST UI Date Picker',
'@version ' + pkg.version,
Expand All @@ -21,14 +44,14 @@ module.exports = function(env, argv) {
].join('\n');

return {
mode: 'development',
mode: isProduction ? 'production' : 'development',
entry: './src/js/index.js',
output: {
library: ['tui', 'DatePicker'],
libraryTarget: 'umd',
path: path.resolve(__dirname, 'dist'),
publicPath: 'dist',
filename: FILENAME
filename: FILENAME + '.js'
},
externals: {
'tui-time-picker': {
Expand Down Expand Up @@ -64,8 +87,9 @@ module.exports = function(env, argv) {
},
plugins: [
new webpack.BannerPlugin(BANNER),
new MiniCssExtractPlugin({filename: pkg.name + '.css'})
new MiniCssExtractPlugin({filename: FILENAME + '.css'})
],
optimization: setOptimization(isMinified),
devServer: {
historyApiFallback: false,
progress: true,
Expand Down

0 comments on commit 0e3410a

Please sign in to comment.