-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
78 lines (75 loc) · 2.57 KB
/
webpack.config.ts
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
/**
* @file defines the webpack configuration.
*/
import path from 'path';
import fs from 'fs';
import { DllReferencePlugin } from 'webpack';
import type { Configuration, WebpackPluginInstance } from 'webpack';
import TerserPlugin from 'terser-webpack-plugin';
import webpackPluginConfig from './webpack.plugins';
function getDirectories(pluginName: string | null | undefined, srcpath: string): string[] {
return (pluginName ? [pluginName] : fs.readdirSync(srcpath))
.filter((value: string) => fs.statSync(path.join(srcpath, value)).isDirectory());
}
/**
* Contains the webpack configuration for building all CKEditor plugins.
*/
export default (env: any): Configuration[] => {
const configs: Configuration[] = [];
// Loop through every subdirectory in src, each a different plugin, and build
// each one in ./js/build.
getDirectories(env ? env['plugin'] : null, './ckeditor5_plugins').forEach((dir: string) => {
const bc: Configuration = {
mode: 'production',
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
format: {
comments: false
}
},
test: /\.js(\?.*)?$/i,
extractComments: false
})
],
moduleIds: 'size'
},
entry: {
path: path.resolve(__dirname, 'ckeditor5_plugins', dir, 'src/index')
},
output: {
path: path.resolve(__dirname, 'js/build'),
filename: `${dir}.js`,
library: ['CKEditor5', dir],
libraryTarget: 'umd',
libraryExport: 'default'
},
plugins: [
// It is possible to require the ckeditor5-dll.manifest.json used in
// core/node_modules rather than having to install CKEditor 5 here.
// However, that requires knowing the location of that file relative to
// where your module code is located.
new DllReferencePlugin({
manifest: require('./node_modules/ckeditor5/build/ckeditor5-dll.manifest.json'), // eslint-disable-line global-require, import/no-unresolved
scope: 'ckeditor5/src',
name: 'CKEditor5.dll'
})
],
module: {
rules: [
{ test: /\.svg$/, use: 'raw-loader' },
{ test: /\.ts$/, loader: 'ts-loader' }
],
},
resolve: {
extensions: ['.ts', '.js', '.json']
}
};
const p: WebpackPluginInstance[] | undefined = webpackPluginConfig[dir];
if (p) bc.plugins = (bc.plugins as WebpackPluginInstance[]).concat(p);
configs.push(bc);
});
return configs;
};