-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
140 lines (125 loc) · 4.4 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* eslint no-var: 0, vars-on-top: 0, prefer-arrow-callback: 0, object-shorthand: 0, prefer-template: 0 */
/* eslint-env node */
require('babel-register');
var noop = require('lodash/noop');
var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var WebpackErrorNotificationPlugin = require('webpack-error-notification');
var StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin;
var CopyPlugin = require('copy-webpack-plugin');
var WebpackRTLPlugin = require('webpack-rtl-plugin');
var isDevelopment = process.env.NODE_ENV === 'development';
var buildTag = process.env.BUILD_TAG;
var taggedPublicURL = process.env.TAGGED_PUBLIC_URL; // Todo: Remove usage after upgrading Webpack. output.publicPath should be set on the fly.
var context = path.join(__dirname, './app');
var entries = ['./client.js'];
if (isDevelopment) {
entries.push('webpack-hot-middleware/client');
}
var NotifyConfigPlugin = function NotifyConfigPlugin() {};
NotifyConfigPlugin.prototype.apply = () => {
console.log("\nWebpack is compiling...\n"); // eslint-disable-line
};
module.exports = {
cache: isDevelopment,
devtool: isDevelopment ? 'eval' : '#source-map',
context: context,
entry: entries,
output: {
path: path.join(__dirname, 'built/public/'),
filename: isDevelopment ? '[name].js' : '/scripts/[name]-[chunkhash].js',
chunkFilename: isDevelopment ? '[name].js' : '/scripts/[name]-[chunkhash].js',
publicPath: !isDevelopment && buildTag && taggedPublicURL ? `${taggedPublicURL}/${buildTag}` : undefined,
},
resolve: {
extensions: ['', '.js', '.jsx', '.scss'],
alias: {
styles: path.join(__dirname, 'app/styles'),
},
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: isDevelopment ? {
presets: [
'es2015',
'stage-1',
'react',
'react-hmre',
],
} : {
presets: [
'es2015',
'stage-1',
'react',
],
},
},
{
test: /\.s?css$/,
loader: isDevelopment ?
'style!rtl-css?sourceMap!postcss!sass?sourceMap&sourceMapContents' :
ExtractTextPlugin.extract('style', 'css?sourceMap!postcss!sass?sourceMap'),
},
{
test: /\.(jpe?g|png|gif|svg)$/,
loader: 'file',
query: isDevelopment ? null : {
name: '/images/[name]-[hash].[ext]',
},
},
{
test: /\.json$/,
loader: 'json',
},
],
},
postcss: function postcss() {
return [autoprefixer];
},
plugins: [
!isDevelopment ? new NotifyConfigPlugin() : noop,
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
HOST: JSON.stringify(process.env.HOST),
PORT: JSON.stringify(process.env.PORT),
BROWSER: JSON.stringify(true),
},
}),
// Optimizations
new webpack.DllReferencePlugin({
manifest: isDevelopment ?
require('./assets/scripts/vendors-manifest.json') :
require('./built/public/vendors-manifest.json'),
context: process.cwd(),
}),
new ExtractTextPlugin(isDevelopment ? 'main.css' : '/styles/main-[contenthash].css'),
!isDevelopment ? new WebpackRTLPlugin({ filename: '/styles/main-[contenthash]-rtl.css' }) : noop,
isDevelopment ? new webpack.HotModuleReplacementPlugin() : noop,
isDevelopment ? new webpack.NoErrorsPlugin() : noop,
isDevelopment ? new WebpackErrorNotificationPlugin() : noop,
!isDevelopment ? // Write out stats.json file to build directory.
new StatsWriterPlugin({
fields: ['assetsByChunkName', 'assets'],
filename: 'chunknames-app.json',
transform: function transform(data) {
const cssRtl = data.assets.find(function findRtlCss(asset) {
return asset.name.split('-').slice(-1)[0] === 'rtl.css';
});
return JSON.stringify({
main: data.assetsByChunkName.main[0],
css: data.assetsByChunkName.main[1],
cssRtl: cssRtl.name,
}, null, 2);
},
}) : noop,
!isDevelopment ?
new CopyPlugin([{ from: path.join(__dirname, 'assets/images'), to: 'images' }], { copyUnmodified: true }) : noop,
],
};