forked from Vanessa219/vditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
168 lines (161 loc) · 4.91 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* @fileoverview webpack.
*
* @author <a href="http://vanessa.b3log.org">Liyuan Li</a>
* @version 0.2.0.1, Jan 4, 2020
*/
const path = require('path')
const webpack = require('webpack')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const {CleanWebpackPlugin} = require('clean-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const TerserPlugin = require('terser-webpack-plugin')
const BundleAnalyzerPlugin = require(
'webpack-bundle-analyzer').BundleAnalyzerPlugin
const pkg = require('./package.json')
const banner = new webpack.BannerPlugin({
banner: `Vditor v${pkg.version} - A markdown editor written in TypeScript.
MIT License
Copyright (c) 2018-present B3log 开源, b3log.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
`,
entryOnly: true,
})
module.exports = [
{
mode: 'production',
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
// chunkFilename: '[name].bundle.js',
// publicPath: `${pkg.cdn}/vditor@${pkg.version}/dist/`,
libraryTarget: 'umd',
library: 'Vditor',
libraryExport: 'default',
globalObject: 'this',
},
entry: {
'index.min': './src/index.ts',
'method.min': './src/method.ts',
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
include: ['index.min.js', 'method.min.js'],
terserOptions: {
format: {
comments: false,
},
},
extractComments: false,
}),
],
},
resolve: {
extensions: ['.ts', '.js', '.scss', 'png'],
},
module: {
rules: [
{
test: /\.png$/,
include: [path.resolve(__dirname, './src/assets/images')],
use: [
'file-loader',
],
},
{
test: /\.js$/,
exclude: '/node_modules/',
use: {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/env',
{
targets: {
browsers: [
'last 2 Chrome major versions',
'last 2 Firefox major versions',
'last 2 Safari major versions',
'last 2 Edge major versions',
'last 2 iOS major versions',
'last 2 ChromeAndroid major versions',
],
},
},
],
],
},
},
},
{
test: /\.ts$/,
use: 'ts-loader',
},
{
test: /\.scss$/,
include: [path.resolve(__dirname, 'src/assets')],
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader', // translates CSS into CommonJS
options: {
url: false,
},
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
['autoprefixer', {grid: true, remove: false}],
],
},
},
},
{
loader: 'sass-loader', // compiles Sass to CSS
},
],
},
],
},
plugins: [
// new BundleAnalyzerPlugin(),
new CleanWebpackPlugin({
cleanOnceBeforeBuildPatterns: [
path.join(__dirname, 'dist')],
}),
new webpack.DefinePlugin({
VDITOR_VERSION: JSON.stringify(pkg.version),
}),
new MiniCssExtractPlugin({
filename: 'index.css',
}),
banner,
new CopyPlugin({
patterns: [
{from: 'src/css', to: 'css'},
{from: 'src/images', to: 'images'},
{from: 'src/js', to: 'js'},
{from: 'types', to: 'types'},
],
}),
],
}]