forked from Paqmind/react-ultimate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config-prod.js
183 lines (153 loc) · 6.29 KB
/
webpack.config-prod.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
import Fs from "fs";
import Path from "path";
import {assoc, map, reduce} from "ramda";
import {Base64} from "js-base64";
import Webpack from "webpack";
import GlobalizePlugin from "globalize-webpack-plugin";
import CommonsChunkPlugin from "webpack/lib/optimize/CommonsChunkPlugin";
import ExtractTextPlugin from "extract-text-webpack-plugin";
// CONSTANTS =======================================================================================
const NODE_MODULES_DIR = Path.join(__dirname, "node_modules");
const SHARED_DIR = Path.join(__dirname, "shared");
const FRONTEND_DIR = Path.join(__dirname, "frontend");
const BACKEND_DIR = Path.join(__dirname, "backend");
const PUBLIC_DIR = Path.join(__dirname, "public");
// Paths to minified library distributions relative to the root node_modules
const MINIFIED_DEPS = [
"moment/min/moment.min.js",
];
const API_AUTH = process.env.hasOwnProperty("API_USER_NAME") && process.env.hasOwnProperty("API_USER_PASS")
? "Basic " + Base64.encode(process.env.API_USER_NAME + ":" + process.env.API_USER_PASS)
: undefined;
const DEFINE = {
"process.env": {
"NODE_ENV": JSON.stringify(process.env.NODE_ENV),
},
"config": {
"api-auth": JSON.stringify(API_AUTH),
},
};
const AUTOPREFIXER = "autoprefixer?{browsers: ['> 5%']}";
// CONFIG ==========================================================================================
export default {
// Compilation target: http://webpack.github.io/docs/configuration.html#target
target: "web",
// Entry files: http://webpack.github.io/docs/configuration.html#entry
entry: {
bundle: "./frontend/app",
vendors: [
"globalize",
"globalize/dist/globalize-runtime/number",
"globalize/dist/globalize-runtime/plural",
"globalize/dist/globalize-runtime/message",
"globalize/dist/globalize-runtime/currency",
"globalize/dist/globalize-runtime/date",
"globalize/dist/globalize-runtime/relative-time"
],
},
// Output files: http://webpack.github.io/docs/configuration.html#output
output: {
// Abs. path to output directory: http://webpack.github.io/docs/configuration.html#output-path
path: PUBLIC_DIR,
// Filename of an entry chunk: http://webpack.github.io/docs/configuration.html#output-filename
filename: "[name].js?[chunkhash]",
// Web path (used to prefix URLs): http://webpack.github.io/docs/configuration.html#output-publicpath
publicPath: "/public/",
// Include pathinfo in output (like `require(/*./test*/23)`): http://webpack.github.io/docs/configuration.html#output-pathinfo
pathinfo: false,
},
// Debug mode: http://webpack.github.io/docs/configuration.html#debug
debug: false,
// Enhance debugging: http://webpack.github.io/docs/configuration.html#devtool
devtool: null,
// Capture timing information: http://webpack.github.io/docs/configuration.html#profile
profile: false,
// http://webpack.github.io/docs/configuration.html#module
module: {
noParse: map(dep => {
return Path.resolve(NODE_MODULES_DIR, dep);
}, MINIFIED_DEPS),
// http://webpack.github.io/docs/loaders.html
loaders: [
// JS https://github.com/babel/babel-loader
{test: /\.(js(\?.*)?)$/, loaders: ["babel?stage=0"], exclude: /node_modules/},
// JSON https://github.com/webpack/json-loader
{test: /\.(json(\?.*)?)$/, loaders: ["json"]},
{test: /\.(json5(\?.*)?)$/, loaders: ["json5"]},
// RAW https://github.com/webpack/raw-loader
{test: /\.(txt(\?.*)?)$/, loaders: ["raw"]},
// URL: https://github.com/webpack/url-loader
{test: /\.(jpg(\?.*)?)$/, loaders: ["url?limit=10000"]},
{test: /\.(jpeg(\?.*)?)$/, loaders: ["url?limit=10000"]},
{test: /\.(png(\?.*)?)$/, loaders: ["url?limit=10000"]},
{test: /\.(gif(\?.*)?)$/, loaders: ["url?limit=10000"]},
{test: /\.(svg(\?.*)?)$/, loaders: ["url?limit=10000"]},
{test: /\.(woff(\?.*)?)$/, loaders: ["url?limit=100000"]},
{test: /\.(woff2(\?.*)?)$/, loaders: ["url?limit=100000"]},
// FILE: https://github.com/webpack/file-loader
{test: /\.(ttf(\?.*)?)$/, loaders: ["file"]},
{test: /\.(eot(\?.*)?)$/, loaders: ["file"]},
{test: /\.(wav(\?.*)?)$/, loaders: ["file"]},
{test: /\.(mp3(\?.*)?)$/, loaders: ["file"]},
// HTML
{test: /\.(html(\?.*)?)$/, loaders: ["html"]},
// MARKDOWN
{test: /\.(md(\?.*)?)$/, loaders: ["html", "markdown"]},
// CSS: https://github.com/webpack/css-loader
{test: /\.(css(\?.*)?)$/, loader: ExtractTextPlugin.extract(`css!${AUTOPREFIXER}`)},
// LESS: https://github.com/webpack/less-loader
{test: /\.(less(\?.*)?)$/, loader: ExtractTextPlugin.extract(`css!${AUTOPREFIXER}!less`)},
],
},
// Module resolving: http://webpack.github.io/docs/configuration.html#resolve
resolve: {
// Abs. path with modules
root: FRONTEND_DIR,
// Additional folders
modulesDirectories: ["web_modules", "node_modules"],
// ???
alias: reduce((memo, dep) => {
let depPath = Path.resolve(NODE_MODULES_DIR, dep);
return assoc(dep.split(Path.sep)[0], depPath, memo);
}, {}, MINIFIED_DEPS),
},
// Loader resolving: http://webpack.github.io/docs/configuration.html#resolveloader
resolveLoader: {
// Abs. path with loaders
root: NODE_MODULES_DIR,
},
// http://webpack.github.io/docs/list-of-plugins.html
plugins: [
new Webpack.NoErrorsPlugin(),
new Webpack.IgnorePlugin(/^vertx$/),
new Webpack.DefinePlugin(DEFINE),
new Webpack.optimize.DedupePlugin(),
new Webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
}),
new Webpack.optimize.CommonsChunkPlugin("vendors", "vendors.js?[chunkhash]"),
new Webpack.optimize.UglifyJsPlugin({mangle: {except: ["$", "window", "document", "console"]}}),
new ExtractTextPlugin("[name].css?[contenthash]"),
new GlobalizePlugin({
production: true,
developmentLocale: "en",
supportedLocales: ["en", "ru"],
messages: "messages/[locale].json",
output: "i18n/[locale].[hash].js"
}),
function () {
this.plugin("done", function (stats) {
let jsonStats = stats.toJson({
chunkModules: true,
});
jsonStats.publicPath = "/public/";
Fs.writeFileSync(
Path.join(PUBLIC_DIR, "assets.json"),
JSON.stringify(jsonStats.assetsByChunkName)
);
});
},
],
};