forked from Automattic/liveblog
-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
119 lines (111 loc) · 3 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
const path = require('path');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const paths = {
entry: './src/react/index.js',
out: './assets',
};
const webpackConfig = {
cache: true,
context: path.resolve(__dirname, './src'),
entry: {
app: path.join(__dirname, paths.entry),
amp: path.join(__dirname, './src/react/amp.js'),
theme: path.join(__dirname, './src/react/theme.js'),
dashboard: path.join(__dirname, './src/react/dashboard.js'),
facebookSdk: path.join(__dirname, './src/react/facebook-sdk.js'),
},
output: {
path: path.join(__dirname, paths.out),
filename: '[name].js?v=[hash:6]',
chunkFilename: '[name].bundle.js?v=[hash:6]',
jsonpFunction: 'wpJsonpLiveBlog',
},
module: {
rules: [
// Run Babel and lint JS
{
test: /\.js$/,
exclude: [/node_modules/],
use: [
{
loader: 'babel-loader',
},
{
loader: 'eslint-loader',
options: {
configFile: '.eslintrc',
emitError: false,
emitWarning: true,
},
},
],
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: false,
minimize: true,
},
},
{
loader: 'postcss-loader',
options: {
plugins: () => [
autoprefixer({
browsers: [
'last 1 version',
'ie >= 11',
],
}),
],
},
},
{
loader: 'sass-loader',
options: {
sourceMap: false,
},
},
],
}),
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
],
}),
},
],
},
plugins: [
new ExtractTextPlugin({ // define where to save the file
filename: '[name].css',
allChunks: true,
}),
// Global vars for checking dev environment.
new webpack.DefinePlugin({
__DEV__: JSON.stringify(process.env.NODE_ENV !== 'production'),
__PROD__: JSON.stringify(process.env.NODE_ENV === 'production'),
__TEST__: JSON.stringify(process.env.NODE_ENV === 'test'),
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
],
};
// Production/Dev Specific Config
if (process.env.NODE_ENV === 'production') {
webpackConfig.plugins.push(new webpack.optimize.UglifyJsPlugin());
} else {
webpackConfig.devtool = 'sourcemap';
}
module.exports = webpackConfig;