forked from gokalakal/woocommerce-gateway-stripe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
126 lines (120 loc) · 3.48 KB
/
webpack.config.js
File metadata and controls
126 lines (120 loc) · 3.48 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
const path = require( 'path' );
const webpack = require( 'webpack' );
const DependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' );
const LiveReloadWebpackPlugin = require( '@kooneko/livereload-webpack-plugin' );
const defaultConfig = require( '@wordpress/scripts/config/webpack.config' );
const defaultConfigOutput = defaultConfig.output;
const isProduction = process.env.NODE_ENV === 'production';
// Exclude jsonpFunction as it is not supported by webpack 5+.
// https://github.com/webpack/webpack.js.org/issues/3942
delete defaultConfigOutput.jsonpFunction;
module.exports = {
...defaultConfig,
output: {
...defaultConfigOutput,
chunkLoadingGlobal: defaultConfig.output.jsonpFunction,
devtoolModuleFilenameTemplate: 'webpack://[resource-path]',
},
devtool:
process.env.NODE_ENV === 'production'
? 'hidden-source-map'
: defaultConfig.devtool,
optimization: {
...defaultConfig.optimization,
minimizer: [
...defaultConfig.optimization.minimizer.map( ( plugin ) => {
if ( plugin.constructor.name === 'TerserPlugin' ) {
// wp-scripts does not allow to override the Terser minimizer sourceMap option, without this
// `devtool: 'hidden-source-map'` is not generated for js files.
plugin.options.sourceMap = true;
}
return plugin;
} ),
],
splitChunks: false,
},
plugins: [
...defaultConfig.plugins.filter(
( plugin ) =>
plugin.constructor.name !==
'DependencyExtractionWebpackPlugin' &&
plugin.constructor.name !== 'LiveReloadPlugin'
),
new DependencyExtractionWebpackPlugin( {
injectPolyfill: true,
} ),
new webpack.DefinePlugin( {
__PAYMENT_METHOD_FEES_ENABLED: JSON.stringify(
process.env.PAYMENT_METHOD_FEES_ENABLED === 'true'
),
} ),
! isProduction &&
new LiveReloadWebpackPlugin( {
port: process.env.WP_LIVE_RELOAD_PORT || 35729,
} ),
],
module: {
...defaultConfig.module,
rules: [
...defaultConfig.module.rules.map( ( rule ) => {
// If the rule doesn't apply to SCSS files, return the rule as is.
if ( ! rule.test.test( 'test.scss' ) ) {
return rule;
}
return {
...rule,
use: [
...rule.use.map( ( useEntry ) => {
if (
useEntry.loader !==
require.resolve( 'sass-loader' )
) {
return useEntry;
}
return {
...useEntry,
options: {
...( useEntry?.options || {} ),
sassOptions: {
...( useEntry?.options?.sassOptions ||
{} ),
quietDeps: true,
},
},
};
} ),
],
};
} ),
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
resolve: {
fullySpecified: false,
},
},
],
},
resolve: {
...defaultConfig.resolve,
extensions: [ '.json', '.js', '.jsx', '.mjs' ],
modules: [ path.join( __dirname, 'client' ), 'node_modules' ],
alias: {
...defaultConfig.resolve.alias,
wcstripe: path.resolve( __dirname, 'client' ),
},
},
entry: {
index: './client/blocks/index.js',
'upe-classic': './client/classic/upe/index.js',
'upe-blocks': './client/blocks/upe/index.js',
'upe-settings': './client/settings/index.js',
'payment-gateways': './client/entrypoints/payment-gateways/index.js',
'express-checkout': './client/entrypoints/express-checkout/index.js',
'express-checkout-settings':
'./client/entrypoints/express-checkout-settings/index.js',
'amazon-pay-settings':
'./client/entrypoints/amazon-pay-settings/index.js',
},
};