webpack.config.js   A
last analyzed

Complexity

Total Complexity 4
Complexity/F 0

Size

Lines of Code 97
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 58
mnd 4
bc 4
fnc 0
dl 0
loc 97
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
const path = require( 'path' );
2
const MiniCSSExtractPlugin = require( 'mini-css-extract-plugin' );
3
const CleanWebpackPlugin = require( 'clean-webpack-plugin' );
4
const WebpackRTLPlugin = require( 'webpack-rtl-plugin' );
5
const wpPot = require( 'wp-pot' );
6
7
const inProduction = 'production' === process.env.NODE_ENV;
8
const mode = inProduction ? 'production' : 'development';
9
10
const config = {
11
	mode,
12
13
	entry: {
14
		admin: [ './assets/src/js/admin/main.js', './assets/src/css/admin/main.scss' ],
15
	},
16
	output: {
17
		path: path.join( __dirname, './assets/dist/' ),
18
		filename: 'js/[name].js',
19
	},
20
21
	// Ensure modules like magnific know jQuery is external (loaded via WP).
22
	externals: {
23
		$: 'jQuery',
24
		jquery: 'jQuery',
25
	},
26
	devtool: ! inProduction ? 'source-map' : '',
27
	module: {
28
		rules: [
29
			// Use Babel to compile JS.
30
			{
31
				test: /\.js$/,
32
				exclude: /node_modules/,
33
				loader: 'babel-loader',
34
			},
35
36
			// Create RTL styles.
37
			{
38
				test: /\.css$/,
39
				use: [ 'style-loader', 'css-loader' ],
40
			},
41
42
			// SASS to CSS.
43
			{
44
				test: /\.scss$/,
45
				use: [
46
					MiniCSSExtractPlugin.loader,
47
					{
48
						loader: 'css-loader',
49
						options: {
50
							sourceMap: true,
51
						},
52
					},
53
					{
54
						loader: 'sass-loader',
55
						options: {
56
							sourceMap: true,
57
							outputStyle: inProduction ? 'compressed' : 'nested',
58
						},
59
					},
60
				],
61
			},
62
		],
63
	},
64
65
	// Plugins. Gotta have em'.
66
	plugins: [
67
		// Removes the "dist" folder before building.
68
		new CleanWebpackPlugin( [ 'assets/dist' ] ),
69
70
		new MiniCSSExtractPlugin( {
71
			filename: 'css/[name].css',
72
		} ),
73
	],
74
};
75
76
if ( inProduction ) {
77
	// Create RTL css.
78
	config.plugins.push(
79
		new WebpackRTLPlugin( {
80
			suffix: '-rtl',
81
			minify: true,
82
		} )
83
	);
84
85
	// POT file.
86
	wpPot( {
87
		package: 'PaiementPro for Give',
88
		domain: 'paiementpro-for-give',
89
		destFile: 'languages/paiementpro-for-give.pot',
90
		relativeTo: './',
91
		src: [ './**/*.php', '!./vendor/**/*' ],
92
		bugReport: 'https://github.com/kohp-ministries/paiementpro-for-give/issues/new',
93
		team: 'PaiementPro Team <[email protected]>',
94
	} );
95
}
96
97
module.exports = config;
98