forked from the-events-calendar/the-events-calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
85 lines (73 loc) · 3.98 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
/**
* External dependencies
*/
const { resolve } = require( 'path' );
const { reduce, zipObject } = require( 'lodash' );
const merge = require( 'webpack-merge' );
const common = require( '@the-events-calendar/product-taskmaster/webpack/common/webpack.config' );
const { getDirectoryNames, getDirectories } = require( '@the-events-calendar/product-taskmaster/webpack/utils/directories' );
const { getJSFileNames, getJSFiles } = require( '@the-events-calendar/product-taskmaster/webpack/utils/files' );
const PLUGIN_SCOPE = 'events';
//
// ────────────────────────────────────────────────────────────────────────────────────── I ──────────
// :::::: G E N E R A T E E V E N T S P L U G I N : : : : : : : :
// ──────────────────────────────────────────────────────────────────────────────────────────────
//
const config = merge( common, {
entry: {
main: resolve( __dirname, './src/modules/index.js' ),
},
output: {
path: __dirname,
library: [ 'tribe', PLUGIN_SCOPE ],
},
} );
//
// ────────────────────────────────────────────────────────────────────────────────────── II ──────────
// :::::: G E N E R A T E W I D G E T S P L U G I N : : : : : : : :
// ────────────────────────────────────────────────────────────────────────────────────────────────
//
const widgetsConfig = merge( common, {
entry: {
widgets: resolve( __dirname, './src/modules/widgets/index.js' ),
},
output: {
path: __dirname,
library: [ 'tribe', PLUGIN_SCOPE, '[name]' ],
},
} );
//
// ──────────────────────────────────────────────────────────────────────────────────────────── III ──────────
// :::::: G E N E R A T E S T Y L E S F R O M V I E W S : : : : : : : :
// ──────────────────────────────────────────────────────────────────────────────────────────────────────
//
const stylePath = resolve( __dirname, './src/styles' );
const styleDirectories = getDirectories( stylePath );
const styleDirectoryNames = getDirectoryNames( stylePath );
const styleEntries = zipObject( styleDirectoryNames, styleDirectories );
const removeExtension = ( str ) => str.slice( 0, str.lastIndexOf( '.' ) );
const entries = reduce( styleEntries, ( result, dirPath, dirName ) => {
const jsFiles = getJSFiles( dirPath );
const jsFileNames = getJSFileNames( dirPath );
const entryNames = jsFileNames.map(
filename => `${ dirName }/${ removeExtension( filename ) }`
);
return {
...result,
...zipObject( entryNames, jsFiles ),
};
}, { } );
const styleConfig = merge( common, {
entry: entries,
output: {
path: __dirname,
},
} );
//
// ─── EXPORT CONFIGS ─────────────────────────────────────────────────────────────
//
module.exports = [
config,
widgetsConfig,
styleConfig,
];