-
Notifications
You must be signed in to change notification settings - Fork 17
/
webpack.demo.config.js
122 lines (118 loc) · 2.91 KB
/
webpack.demo.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
'use strict'
const isWsl = require('is-wsl')
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebPackPlugin = require('html-webpack-plugin')
const src = path.join(__dirname, 'src')
module.exports = (env) => {
const isDev = process.env.NODE_ENV === 'development'
return {
mode: isDev ? 'development' : 'production',
entry: path.join(src, 'index.ts'),
output: {
path: path.join(__dirname, 'demo'),
filename: './index.[contenthash].js',
library: 'html2md',
libraryExport: 'default',
globalObject: 'this',
libraryTarget: 'umd',
},
devtool: isDev ? 'cheap-module-source-map' : false,
optimization: isDev
? {}
: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
parse: {
ecma: 8,
},
compress: {
ecma: 5,
warnings: false,
comparisons: false,
inline: 2,
},
mangle: {
safari10: true,
},
output: {
ecma: 5,
comments: false,
ascii_only: true,
},
},
parallel: !isWsl,
cache: true,
}),
],
},
resolve: {
extensions: ['.ts', '.js', '.json'],
},
module: {
rules: [
{ parser: { requireEnsure: false } },
{
test: /\.tsx?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.(js)$/,
include: path.resolve(__dirname, 'src'),
loader: 'babel-loader',
options: isDev
? {
cacheDirectory: true,
cacheCompression: true,
compact: true,
}
: {},
},
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: () => [
require('postcss-flexbugs-fixes'),
require('postcss-preset-env')({
stage: 3,
}),
],
},
},
],
},
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
},
],
},
],
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebPackPlugin({
template: './index.html',
filename: './index.html',
}),
],
devServer: isDev
? {
clientLogLevel: 'none',
overlay: true,
}
: {},
}
}