This repository has been archived by the owner on Sep 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
144 lines (132 loc) · 4.07 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
141
142
143
144
var resolveHere = require("path").resolve.bind(null, __dirname);
var assignDeep = require("assign-deep");
var values = require("object-values");
var path = require("path");
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var packageJson = require("./package.json");
var env = process.env.NODE_ENV || "development";
var loaders = {
common: {
js: { test: /\.js$/, include: [resolveHere("src")], loader: "babel" },
css: { test: /\.css$/, loader: "style!css?modules!postcss" },
// Images
png: { test: /\.png$/, loader: "url?limit=8192&mimetype=image/png" },
gif: { test: /\.gif$/, loader: "url?limit=8192&mimetype=image/gif" },
jpg: { test: /\.jpe?g$/, loader: "file" },
svg: { test: /\.svg$/, loader: "url?limit=8192&mimetype=image/svg+xml" },
// Fonts
woff2: {
test: /\.woff2$/,
loader: "url?limit=8192&mimetype=application/font-woff2"
},
woff: {
test: /\.woff$/,
loader: "url?limit=8192&mimetype=application/font-woff"
},
ttf: { test: /\.ttf$/, loader: "file" },
eot: { test: /\.eot$/, loader: "file" },
// Other
json: { test: /\.json$/, loader: "json" },
html: { test: /\.html$/, loader: "file?name=[name].[ext]" }
},
development: {
css: {
// loader: 'style!css?modules&localIdentName=[name]-[local]-[hash:base64:5]!postcss' // For hashed names. DON'T USE, because many CSS classes are included in JS as plain text
loader: "style!css?modules&localIdentName=[local]!postcss"
}
},
production: {
css: {
// loader: ExtractTextPlugin.extract('style', 'css?modules&localIdentName=[name]-[local]-[hash:base64:5]!postcss')
loader: ExtractTextPlugin.extract(
"style",
"css?modules&localIdentName=[local]!postcss"
)
}
}
};
var webpackConfig = {
common: {
output: {
publicPath: "",
path: resolveHere("build"),
filename: "[name].[hash].js"
},
resolve: {
root: resolveHere("src")
},
module: {
loaders: values(assignDeep(loaders.common, loaders[env])),
noParse: [/\.min\.js$/]
},
postcss: [
require("postcss-nested")(),
require("postcss-custom-media")({
extensions: {
"--narrow-view": "(max-width: 850px)"
}
}),
require("postcss-clearfix")(),
require("autoprefixer")({ browsers: ["last 2 versions"] })
]
},
development: {
entry: {
app: [
"webpack-hot-middleware/client?noInfo=true&reload=true",
resolveHere("src/index")
]
},
output: {
pathinfo: true
},
publicPath: "/",
devtool: "#eval-source-map",
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
__DEV__: JSON.stringify(true),
"process.env.NODE_ENV": JSON.stringify("development")
}),
new HtmlWebpackPlugin({
title: packageJson.name,
template: "src/index.html",
favicon: "src/assets/ixt_favicon-32.png",
inject: "body",
description: packageJson.description,
version: packageJson.version
})
]
},
production: {
entry: {
app: resolveHere("src/index")
},
publicPath: "https://galaxy-of-covers.interactivethings.io/",
plugins: [
new webpack.DefinePlugin({
__DEV__: JSON.stringify(false),
"process.env.NODE_ENV": JSON.stringify("production")
}),
new HtmlWebpackPlugin({
title: packageJson.name,
template: "src/index.html",
favicon: "src/assets/ixt_favicon-32.png",
inject: "body",
description: packageJson.description,
version: packageJson.version
}),
new ExtractTextPlugin("style.[contenthash].css", { allChunks: true }),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
}
};
module.exports = assignDeep(webpackConfig.common, webpackConfig[env]);