-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config-old.js
More file actions
381 lines (370 loc) · 12.2 KB
/
Copy pathwebpack.config-old.js
File metadata and controls
381 lines (370 loc) · 12.2 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
const webpack = require('webpack');
const path = require('path');
// variables
const isProduction = process.argv.indexOf('-p') >= 0 || process.env.NODE_ENV == "production";
const sourcePath = path.join(__dirname, './src');
const outPath = path.join(__dirname, './dist');
// plugins
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractSASS = new ExtractTextPlugin('[name].css');
const autoPrefixer = require('autoprefixer');
const RemoteDebuggerPlugin = require('remote-debugger-webpack').default;
// console.log("RDP", RemoteDebuggerPlugin);
module.exports = function (publicPath) {
console.log("WP IS PRODUCTION? ", isProduction);
const frontEntry = isProduction ?
[
'react',
'react-dom',
'react-redux',
'react-router',
'redux',
path.resolve(__dirname, 'src', 'main.tsx')] :
[
'eventsource-polyfill', // Necessary for hot reloading with IE
`webpack-hot-middleware/client?reload=true&path=${publicPath}__webpack_hmr`,
path.resolve(__dirname, 'src', 'main.tsx')
];
const sassEntry = /*ExtractTextPlugin.extract({
fallback: 'style-loader',
//resolve-url-loader may be chained before sass-loader if necessary
use:*/ [
/*{
loader: "style-loader", // creates style nodes from JS strings
options: {
attrs: {id: "estilos"}
}
},*/
/*
{
loader: "style-loader", // creates style nodes from JS strings
options: {
insertInto: 'html::shadow #root',
attrs: {id: "estilos"}
}
},*/
{
loader: "css-loader", // translates CSS into CommonJS
options: {
sourceMap: true,
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
plugins: [
autoPrefixer({
browsers: ['last 10 versions']
})
]
}
},
'resolve-url-loader',
{
loader: "sass-loader", // compiles Sass to CSS
options: {
sourceMap: true,
}
}
]
//});
const devtool = isProduction ? 'source-map' : 'inline-source-map';//'source-map'; //'source-map' : 'source-map'; //'cheap-module-source-map' /*'inline-source-map'*/;
const plugins = isProduction ? [] :
[
// Tell webpack we want hot reloading
new webpack.HotModuleReplacementPlugin(),
/*new RemoteDebuggerPlugin({
appendScriptTag: false, // whether inject socket script tag
weinreServer: true, // whether run weinre server in background when run webpack
weinreOption: { // see: http://people.apache.org/~pmuellr/weinre/docs/latest/Running.html
httpPort: undefined, // if not define, it can use a idle port
boundHost: undefined, // if not define, it can use local ip( not 127.0.0.1)
verbose: true,
debug: true,
readTimeout: 5,
deathTimeout: 15,
defaultId: 'anonymous', // define a default id, if define 'auto', it will give you a random id. format is `${platform}-${browser}-${uid}`
},
httpProxyServer: true, // whether run http proxy in background when run webpack
httpProxyOption: {
port: 9877,
},
}),*/
];
plugins.push(
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
},
__ENV__: JSON.stringify(process.env.NODE_ENV),
__DIVE_ENV__: JSON.stringify('PRO'),
}),
/*
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendor.bundle.js',
minChunks: function (module) {
// this assumes your vendor imports exist in the node_modules directory
return module.resource && (/node_modules/).test(module.resource);
}
}),*/
new webpack.optimize.AggressiveMergingPlugin(),
/*new ExtractTextPlugin(
'DiveSDK.[name].css', {
disable: false,
allChunks: true
}
),*/
new HtmlWebpackPlugin({
template: 'index.html',
})
);
const sourceMapPath = "file:///";
if (process.env.NODE_ENV === "production") {
plugins.push(
new UglifyJSPlugin({
sourceMap: {
base: "file:///",
},
warnings: "verbose",
// Eliminate comments
comments: true,
// Compression specific options
compress: {
join_vars: true,
if_return: true,
unused: true,
loops: true,
booleans: true,
conditionals: true,
dead_code: true,
// remove warnings
warnings: false,
// Drop console statements
drop_console: false,//true
},
})
);
}
const config = {
watch: false,
context: sourcePath,
entry: {
front: frontEntry,
/*styles: [
// 'webpack-hot-middleware/client?reload=true',
path.resolve(__dirname, 'src', 'scss', 'main.scss'),
], *//*
vendor: [
'babel-polyfill',
'react',
'react-dom',
'react-redux',
'react-router',
'redux'
]*/
},
output: {
path: outPath,
filename: 'DiveSDK.[name].js',
library: ['DiveSDK', "[name]"],
libraryTarget: "var",
publicPath: publicPath,
},
target: 'web',
resolve: {
alias: {
Components: path.resolve(__dirname, 'src', 'components', 'index'),
Services: path.resolve(__dirname, 'src', 'services', 'index'),
Reducers: path.resolve(__dirname, 'src', 'reducers', 'index'),
Actions: path.resolve(__dirname, 'src', 'actions', 'index'),
Types: path.resolve(__dirname, 'types', 'index'),
Containers: path.resolve(__dirname, 'src', 'containers', 'index'),
Constants: path.resolve(__dirname, 'src', 'constants'),
HOC: path.resolve(__dirname, 'src', 'HOC', 'index'),
CardModules: path.resolve(__dirname, 'src', 'components', 'cardDetailComponents', 'cardModules', 'index'),
Theme: path.resolve(__dirname, 'src', 'scss', 'theme', 'index'),
},
extensions: ['.js', '.ts', '.tsx'],
// Fix webpack's default behavior to not load packages with jsnext:main module
// https://github.com/Microsoft/TypeScript/issues/11677
mainFields: ['main']
},
module: {
loaders: [
// .ts, .tsx
{
test: /\.(ts|tsx)?$/,
exclude: /node_modules/,
use: ['cache-loader', 'babel-loader', 'awesome-typescript-loader?configFileName=tsconfig.json'],
},
// css
{
test: /\.css$/,
use: {
loader: "style-loader", // creates style nodes from JS strings
options: {
sourceMap: true,
insertInto: '#root',
attrs: { id: "estilos" }
}
}
},
{
test: /\.scss?$/,
exclude: /node_modules/,
use: isProduction ? sassEntry : ['css-hot-loader'].concat(sassEntry),
},
// static assets
{ test: /\.html$/, use: 'html-loader' },
{
test: /\.(jpe?g|png|gif|svg)$/,
exclude: [/node_modules/, path.resolve(__dirname, '..', 'src', 'assets', 'fonts')],
loaders: [
{
loader: 'file-loader',
query: {
name: 'assets/[hash].[ext]',
//name: 'https://cdn.dive.tv/sdkweb/assets/[hash].[ext]',
}
},
{
loader: 'image-webpack-loader',
query: {
mozjpeg: {
progressive: true,
},
gifsicle: {
interlaced: false,
},
optipng: {
optimizationLevel: 4,
},
pngquant: {
quality: '75-90',
speed: 3,
},
},
},
],
},/*
{
test: /\.(svg)$/,
exclude: ['node_modules', path.resolve(__dirname, '..', 'src', 'assets', 'fonts')],
use: [
{
loader: "file-loader",
query: {
name: 'assets/svg/[name].[ext]'
}
}
]
},*/
{ test: /\.json$/, use: 'json-loader' }
],
},
plugins: plugins,
devtool,
node: {
// workaround for webpack-dev-server issue
// https://github.com/webpack/webpack-dev-server/issues/60#issuecomment-103411179
fs: 'empty',
net: 'empty'
},
target: 'web', // Make web variables accessible to webpack, e.g. window,
};
if (!isProduction) {
config.devServer = {
hot: true,
inline: true,
contentBase: sourcePath,
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, content-type, Authorization"
},
stats: {
warnings: false
},
};
}
config.stats = "minimal"; /*{
// Add asset Information
assets: true,
// Sort assets by a field
assetsSort: "field",
// Add information about cached (not built) modules
cached: true,
// Show cached assets (setting this to `false` only shows emitted files)
cachedAssets: true,
// Add children information
children: true,
// Add chunk information (setting this to `false` allows for a less verbose output)
chunks: true,
// Add built modules information to chunk information
chunkModules: true,
// Add the origins of chunks and chunk merging info
chunkOrigins: true,
// Sort the chunks by a field
chunksSort: "field",
// `webpack --colors` equivalent
colors: true,
// Display the distance from the entry point for each module
depth: false,
// Display the entry points with the corresponding bundles
entrypoints: false,
// Add errors
errors: true,
// Add details to errors (like resolving log)
errorDetails: true,
// // Exclude assets from being displayed in stats
// // This can be done with a String, a RegExp, a Function getting the assets name
// // and returning a boolean or an Array of the above.
// excludeAssets: "filter" | /filter/ | (assetName) => ... return true|false |
// ["filter"] | [/filter/] | [(assetName) => ... return true|false],
// // Exclude modules from being displayed in stats
// // This can be done with a String, a RegExp, a Function getting the modules source
// // and returning a boolean or an Array of the above.
// excludeModules: "filter" | /filter/ | (moduleSource) => ... return true|false |
// ["filter"] | [/filter/] | [(moduleSource) => ... return true|false],
// // See excludeModules
// exclude: "filter" | /filter/ | (moduleSource) => ... return true|false |
// ["filter"] | [/filter/] | [(moduleSource) => ... return true|false],
// Add the hash of the compilation
hash: true,
// Set the maximum number of modules to be shown
maxModules: 15,
// Add built modules information
modules: true,
// Sort the modules by a field
modulesSort: "field",
// Show dependencies and origin of warnings/errors (since webpack 2.5.0)
moduleTrace: true,
// Show performance hint when file size exceeds `performance.maxAssetSize`
performance: true,
// Show the exports of the modules
providedExports: false,
// Add public path information
publicPath: true,
// Add information about the reasons why modules are included
reasons: true,
// Add the source code of modules
source: true,
// Add timing information
timings: true,
// Show which exports of a module are used
usedExports: false,
// Add webpack version information
version: true,
// Add warnings
warnings: true,
// // Filter warnings to be shown (since webpack 2.4.0),
// // can be a String, Regexp, a function getting the warning and returning a boolean
// // or an Array of a combination of the above. First match wins.
// warningsFilter: "filter" | /filter/ | ["filter", /filter/] | (warning) => ... return true|false
};*/
return config;
}