forked from johngodley/redirection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
112 lines (106 loc) · 2.67 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
111
112
/** @format */
const path = require( 'path' );
const webpack = require( 'webpack' );
// PostCSS plugins
const cssnext = require( 'postcss-cssnext' );
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.js' ) ],
output: {
path: path.join( __dirname ),
filename: 'redirection.js',
chunkFilename: 'redirection-[name]-[chunkhash].js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader?cacheDirectory',
},
{
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', '.jsx', '.json', '.scss', '.css' ],
modules: [ path.resolve( __dirname, 'client' ), 'node_modules' ],
},
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 webpack.LoaderOptionsPlugin( {
options: {
postcss: [
postcssFocus(),
cssnext( {
browsers: [ 'last 2 versions', 'IE > 10' ],
} ),
postcssReporter( {
clearMessages: true,
} ),
],
},
} ),
],
watchOptions: {
ignored: [ /node_modules/ ],
},
performance: {
hints: false,
},
};
if ( isProduction() ) {
config.plugins.push( new webpack.LoaderOptionsPlugin( { minimize: true } ) );
config.module.rules.push( { test: /\.js$/, loader: 'webpack-remove-debug' } );
} else {
config.output.publicPath = getDevUrl;
config.devtool = 'inline-source-map';
config.entry.unshift( 'webpack/hot/only-dev-server' );
config.entry.unshift( 'webpack-dev-server/client?' + getDevUrl );
config.entry.unshift( 'react-hot-loader/patch' );
config.devServer = {
historyApiFallback: {
index: '/',
},
contentBase: path.resolve( __dirname ),
publicPath: getDevUrl,
headers: { 'Access-Control-Allow-Origin': '*' },
hot: true,
stats: {
colors: true,
hash: false,
version: true,
timings: true,
assets: true,
chunks: false,
modules: false,
reasons: false,
children: false,
source: false,
errors: true,
errorDetails: true,
warnings: false,
publicPath: false,
},
};
}
module.exports = config;