-
-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathwebpack.config.js
More file actions
92 lines (81 loc) · 2.1 KB
/
Copy pathwebpack.config.js
File metadata and controls
92 lines (81 loc) · 2.1 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
const path = require( 'path' );
const glob = require( 'glob' );
const CopyWebpackPlugin = require( 'copy-webpack-plugin' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const dataviewsStyleDir = path.join(
path.dirname( require.resolve( '@wordpress/dataviews/package.json' ) ),
'build-style'
);
const blocksConfig = {
...defaultConfig[ 0 ],
entry: () => {
const entries = defaultConfig[ 0 ].entry();
// Shared styles registered as jobplace-{name} in PHP.
glob.sync( './src/styles/*.scss' ).forEach( ( file ) => {
const name = path.basename( file, '.scss' );
entries[ `styles/${ name }` ] = path.resolve( __dirname, file );
} );
entries.index = path.resolve( __dirname, './src/index.tsx' );
return entries;
},
output: {
...defaultConfig[ 0 ].output,
path: path.resolve( __dirname, 'build' ),
},
};
if ( 'production' !== process.env.NODE_ENV ) {
blocksConfig.devServer = {
devMiddleware: {
writeToDisk: true,
},
allowedHosts: 'all',
host: 'localhost',
port: 8887,
proxy: {
'/build': {
pathRewrite: {
'^/build': '',
},
},
},
};
}
blocksConfig.plugins = [
...( blocksConfig.plugins || [] ),
new CopyWebpackPlugin( {
patterns: [
{
from: path.join( dataviewsStyleDir, 'style.css' ),
to: 'dataviews.css',
},
{
from: path.join( dataviewsStyleDir, 'style-rtl.css' ),
to: 'dataviews-rtl.css',
},
],
} ),
];
const modulesConfig = {
...defaultConfig[ 1 ],
entry: () => {
const entries = {};
glob.sync( './src/scripts/**/index.js' ).forEach( ( file ) => {
const relative = file.replace( /^\.\//, '' );
const name = relative
.replace( /^src\/scripts\//, '' )
.replace( /\/index\.js$/, '' );
entries[ `scripts/${ name }/index` ] = path.resolve( __dirname, file );
} );
return entries;
},
output: {
...defaultConfig[ 1 ].output,
path: path.resolve( __dirname, 'build' ),
},
externals: {
...defaultConfig[ 1 ]?.externals,
'@jobplace/api-fetch': '@jobplace/api-fetch',
'@jobplace/jobs-service': '@jobplace/jobs-service',
},
};
module.exports = [ blocksConfig, modulesConfig ];