Created
April 28, 2017 10:50
-
-
Save igmoweb/689377462c96113cfcfd5279e9074ece to your computer and use it in GitHub Desktop.
Webpack with development/production configs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require( 'path' ); | |
// Configuración común para desarrollo y producción | |
var config = { | |
entry: [ | |
'./src/index.js' | |
], | |
output: { | |
filename: 'app.js', | |
path: path.resolve( __dirname, 'build' ) | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
loader: 'babel-loader', | |
options: { | |
presets: [ 'es2015', 'react' ] | |
}, | |
include: [ | |
path.resolve( __dirname, 'src/' ) | |
] | |
} | |
] | |
} | |
}; | |
// module.exports ahora es una función que recibe la variable env | |
module.exports = function( env ) { | |
var production = 'prod' === env; | |
if ( production ) { | |
config.devtool = 'source-map'; | |
} | |
else { | |
config.devtool = 'cheap-module-eval-source-map'; | |
} | |
// ¡No olvidar retornar el objecto config! | |
return config; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment