-
Notifications
You must be signed in to change notification settings - Fork 27
/
getwebpackconfig.js
107 lines (86 loc) · 2.59 KB
/
getwebpackconfig.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
/**
* @license Copyright (c) 2003-2024, CKSource Holding sp. z o.o. All rights reserved.
* For licensing, see LICENSE.md.
*/
import path from 'path';
import webpack from 'webpack';
import { loaders } from '@ckeditor/ckeditor5-dev-utils';
import getDefinitionsFromFile from '../getdefinitionsfromfile.js';
import TreatWarningsAsErrorsWebpackPlugin from './treatwarningsaserrorswebpackplugin.js';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath( import.meta.url );
const __dirname = path.dirname( __filename );
/**
* @param {object} options
* @returns {object}
*/
export default function getWebpackConfigForAutomatedTests( options ) {
const definitions = Object.assign( {}, getDefinitionsFromFile( options.identityFile ) );
const config = {
mode: 'development',
watchOptions: {
aggregateTimeout: 500
},
plugins: [
new webpack.DefinePlugin( definitions ),
new webpack.ProvidePlugin( {
Buffer: [ 'buffer', 'Buffer' ],
process: 'process/browser.js'
} )
],
resolve: {
fallback: {
'timers': false
},
extensions: options.resolveJsFirst ?
[ '.js', '.ts', '.json' ] :
[ '.ts', '.js', '.json' ],
extensionAlias: {
'.js': [ '.ts', '.js' ]
}
},
module: {
rules: [
options.coverage ? loaders.getCoverageLoader( { files: options.files } ) : null,
loaders.getIconsLoader(),
loaders.getStylesLoader( {
themePath: options.themePath,
minify: true
} ),
loaders.getTypeScriptLoader( { configFile: options.tsconfig } ),
loaders.getFormattedTextLoader()
].filter( Boolean )
},
resolveLoader: {
modules: [
'node_modules',
path.resolve( __dirname, '..', '..', '..', 'node_modules' )
]
},
output: {
// Get rid of the "webpack://" protocol to make the paths clickable in the terminal.
devtoolModuleFilenameTemplate: info => info.resourcePath
}
};
if ( options.sourceMap ) {
// After bumping the webpack to v5 and other related tools/libs/whatever, the source maps stopped working for unknown reasons.
// The only way to make them work again was to use the inline source maps.
//
// See https://github.com/ckeditor/ckeditor5/issues/11006.
config.devtool = 'inline-source-map';
// Since webpack v5 it looks like splitting out the source code into the commons and runtime chunks broke the source map support.
config.optimization = {
runtimeChunk: false,
splitChunks: false
};
}
if ( options.cache ) {
config.cache = {
type: 'filesystem'
};
}
if ( options.production ) {
config.plugins.push( new TreatWarningsAsErrorsWebpackPlugin() );
}
return config;
}