-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.js
More file actions
100 lines (97 loc) · 2.94 KB
/
webpack.config.js
File metadata and controls
100 lines (97 loc) · 2.94 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
const path = require( 'path' );
const CopyWebpackPlugin = require('copy-webpack-plugin');
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
const TEMPLATIQ_NAMESPACE = '@templatiq/';
const devHost = 'templatiq.test';
/**
* Given a string, returns a new string with dash separators converted to
* camelCase equivalent. This is not as aggressive as `_.camelCase` in
* converting to uppercase, where Lodash will also capitalize letters
* following numbers.
*
* @param {string} string Input dash-delimited string.
* @return {string} Camel-cased string.
*/
function camelCaseDash( string ) {
return string.replace( /-([a-z])/g, ( _, letter ) => letter.toUpperCase() );
}
const chunkUniqueKey = Date.now().toString();
module.exports = {
...defaultConfig,
entry: {
'js/admin': './src/js/admin/index.js',
'js/index': './src/js/frontend/index.js',
'js/onboarding': './src/js/onboarding/index.js',
'css/global': './src/sass/global.scss',
'vendor/elementor-style': './assets-vendor/elementor-editor.css',
'vendor/elementor-script': './assets-vendor/elementor-editor.js',
},
output: {
path: path.resolve( __dirname, './assets' ),
filename: '[name].js',
chunkFilename: '[name].js?ver=' + chunkUniqueKey,
clean: false,
},
plugins: [
...defaultConfig.plugins.filter(
( plugin ) =>
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
),
new DependencyExtractionWebpackPlugin( {
requestToExternal( request ) {
if ( request.startsWith( TEMPLATIQ_NAMESPACE ) ) {
return [
'templatiq',
camelCaseDash(
request.substring( TEMPLATIQ_NAMESPACE.length )
),
];
}
},
requestToHandle( request ) {
if ( request.startsWith( TEMPLATIQ_NAMESPACE ) ) {
return `templatiq/${ camelCaseDash(
request.substring( TEMPLATIQ_NAMESPACE.length )
) }`;
}
},
} ),
new CopyWebpackPlugin({
patterns: [
{ from: 'src/svg', to: 'svg' },
],
}),
],
resolve: {
alias: {
'@root/style': path.resolve( __dirname, 'src/js/style.js' ),
'@components': path.resolve( __dirname, 'src/js/components' ),
'@modules': path.resolve( __dirname, 'src/js/modules' ),
'@layout': path.resolve( __dirname, 'src/js/layout' ),
'@data': path.resolve( __dirname, 'src/js/data' ),
'@store': path.resolve( __dirname, 'src/js/store' ),
'@hooks': path.resolve( __dirname, 'src/js/hooks' ),
'@helper': path.resolve( __dirname, 'src/js/helper' ),
'@icon': path.resolve( __dirname, 'src/svg/icon' ),
'@images': path.resolve( __dirname, 'src/svg' ),
'@assets': path.resolve( __dirname, 'assets' ),
},
},
devServer: {
devMiddleware: {
writeToDisk: true,
},
allowedHosts: 'auto',
port: 8887,
host: devHost,
proxy: {
'./build': {
pathRewrite: {
'^./build': '',
},
},
},
headers: { 'Access-Control-Allow-Origin': '*' },
},
};