-
Notifications
You must be signed in to change notification settings - Fork 140
/
webpack.config.js
110 lines (104 loc) · 2.58 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
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
/** @format */
const path = require( 'path' );
const webpack = require( 'webpack' );
const TerserPlugin = require( 'terser-webpack-plugin' );
// PostCSS plugins
const postcssPresetEnv = require( 'postcss-preset-env' );
const postcssFocus = require( 'postcss-focus' );
const postcssReporter = require( 'postcss-reporter' );
const isProduction = () => process.env.NODE_ENV === 'production';
const getDevUrl = 'http://localhost:3312/';
const pkg = require( './package.json' );
const config = {
entry: [ path.join( __dirname, 'client', 'index.tsx' ) ],
output: {
path: path.join( __dirname ),
filename: 'redirection.js',
chunkFilename: 'redirection-[name]-[chunkhash].js',
},
module: {
rules: [
{
test: /\.(ts|js|tsx)$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.json$/,
loader: 'json-loader',
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [ 'style-loader', 'css-loader', 'postcss-loader', 'sass-loader' ],
},
{
test: [ path.resolve( __dirname, 'node_modules/redbox-react' ) ],
use: 'null-loader',
},
],
},
resolve: {
extensions: [ '.js', '.ts', '.tsx', '.json', '.scss', '.css' ],
modules: [ path.resolve( __dirname, 'client' ), 'node_modules' ],
},
externals: {
'@wordpress/i18n': 'wp.i18n'
},
plugins: [
new webpack.BannerPlugin( 'Redirection v' + pkg.version ),
new webpack.DefinePlugin( {
'process.env': { NODE_ENV: JSON.stringify( process.env.NODE_ENV || 'development' ) },
REDIRECTION_VERSION: "'" + pkg.version + "'",
} ),
// new BundleAnalyzerPlugin(),
new webpack.LoaderOptionsPlugin( {
options: {
postcss: [
postcssFocus(),
postcssPresetEnv( {
browsers: [ 'last 2 versions', 'IE > 10' ],
} ),
postcssReporter( {
clearMessages: true,
} ),
],
},
} ),
],
watchOptions: {
ignored: [ 'node_modules/**' ],
},
performance: {
hints: false,
},
optimization: {
minimize: isProduction(),
minimizer: [
new TerserPlugin( {
parallel: true,
extractComments: {
condition: true,
banner: () => {
return 'Redirection v' + pkg.version + ' - please refer to license.txt for license information';
},
},
} ),
],
},
};
if ( isProduction() ) {
config.plugins.push( new webpack.LoaderOptionsPlugin( { minimize: true } ) );
} else {
config.output.publicPath = getDevUrl;
config.devtool = 'inline-source-map';
config.devServer = {
historyApiFallback: {
index: '/',
},
//disableHostCheck: true,
host: "latest.local",
headers: { 'Access-Control-Allow-Origin': '*' },
};
}
module.exports = config;