forked from slab/quill
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.js
More file actions
166 lines (158 loc) · 3.58 KB
/
Copy pathwebpack.config.js
File metadata and controls
166 lines (158 loc) · 3.58 KB
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
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const pkg = require('../package.json');
const bannerPack = new webpack.BannerPlugin({
banner: [
`Quill Editor v${pkg.version}`,
'https://quilljs.com/',
'Copyright (c) 2014, Jason Chen',
'Copyright (c) 2013, salesforce.com',
].join('\n'),
entryOnly: true,
});
const constantPack = new webpack.DefinePlugin({
QUILL_VERSION: JSON.stringify(pkg.version),
});
const source = [
'quill.js',
'core.js',
'blots',
'core',
'formats',
'modules',
'test',
'themes',
'ui',
].map(file => {
return path.resolve(__dirname, '..', file);
});
const jsRules = {
test: /\.js$/,
include: source,
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',
],
ie: '11',
},
},
],
],
},
},
],
};
const svgRules = {
test: /\.svg$/,
include: [path.resolve(__dirname, '../assets/icons')],
use: [
{
loader: 'html-loader',
options: {
minimize: true,
},
},
],
};
const stylRules = {
test: /\.styl$/,
include: [path.resolve(__dirname, '../assets')],
use: [MiniCssExtractPlugin.loader, 'css-loader', 'stylus-loader'],
};
const tsRules = {
test: /\.ts$/,
use: [
{
loader: 'ts-loader',
options: {
compilerOptions: {
declaration: false,
module: 'commonjs',
sourceMap: true,
target: 'es5',
},
transpileOnly: true,
},
},
],
};
const baseConfig = {
mode: 'development',
context: path.resolve(__dirname, '..'),
entry: {
'quill.js': ['./quill.js'],
'quill.core.js': ['./core.js'],
'quill.core': './assets/core.styl',
'quill.bubble': './assets/bubble.styl',
'quill.snow': './assets/snow.styl',
'unit.js': './test/unit.js',
},
output: {
filename: '[name]',
library: 'Quill',
libraryExport: 'default',
libraryTarget: 'umd',
path: path.resolve(__dirname, '../dist/'),
},
resolve: {
alias: {
parchment: path.resolve(
__dirname,
'../node_modules/parchment/src/parchment',
),
},
extensions: ['.js', '.styl', '.ts'],
},
module: {
rules: [jsRules, stylRules, svgRules, tsRules],
noParse: [
/\/node_modules\/clone\/clone\.js$/,
/\/node_modules\/eventemitter3\/index\.js$/,
/\/node_modules\/extend\/index\.js$/,
],
},
plugins: [
bannerPack,
constantPack,
new MiniCssExtractPlugin({
filename: '[name].css',
}),
],
devServer: {
contentBase: path.resolve(__dirname, '../dist'),
hot: false,
port: process.env.npm_package_config_ports_webpack,
stats: 'minimal',
disableHostCheck: true,
},
};
module.exports = env => {
if (env && env.minimize) {
const { devServer, ...prodConfig } = baseConfig;
return {
...prodConfig,
mode: 'production',
entry: { 'quill.min.js': './quill.js' },
devtool: 'source-map',
};
}
if (env && env.coverage) {
baseConfig.module.rules[0].use[0].options.plugins = ['istanbul'];
return baseConfig;
}
return baseConfig;
};