forked from LilliamHaro/bike-hack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.prod.js
More file actions
71 lines (69 loc) · 2.07 KB
/
Copy pathwebpack.config.prod.js
File metadata and controls
71 lines (69 loc) · 2.07 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
const { resolve } = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
context: resolve(__dirname, 'src'),
entry: './index.js', // archivo de entrada
output: { // archivos de salida
filename: 'app.min.js', // archivo de salida
path: resolve(__dirname, 'public'), // ruta donde va a estar el archivo, si deseo que sea aqui mismo pongo _dirname
publicPath: ''
},
module: {
rules: [
{
test: /\.js$/, // todos los `js`
exclude: /node_modules/,
use: {
loader: 'babel-loader', // ignoramos archivos dentro de node_modules
options: {
// Config babel
presets: [
'env',
'react',
'react-boilerplate'
]
}
}
},
{
test: /\.css$/, // todos los archivos `css`
exclude: /node_modules/,
use: [
{ loader: 'style-loader' }, // primero creamos un tag `style`
{ loader: 'css-loader' } // y le injetamos el `css`
]
}
]
},
plugins: [
// concatena los modulos importados
// cocatena todos los plugins en uno solo y los ejecuta, antes se ejecutaba cada uno y no era óptimo
new webpack.optimize.ModuleConcatenationPlugin(),
// inyecta el codigo dentro del `index.html`
// Genera el html que se mostrará
new HtmlWebpackPlugin({
template: resolve(__dirname, 'public', 'index.html'),
filename: 'index.html',
}),
// optimizacion 1
new webpack.optimize.OccurrenceOrderPlugin(),
// optimizacion 2
// migrar webpack 1 a webpack 2, para algunos loaders que no soportan versiones actuales
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
// optimizacion 3
// minifica
new webpack.optimize.UglifyJsPlugin({
beautify: false
}),
// definimos variable global de **entorno de producción
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production')
}
})
]
}