Last active
March 7, 2019 15:16
-
-
Save molavec/9aa156a791f677273a3a4f6079caa6a9 to your computer and use it in GitHub Desktop.
[webpack - configuración] snippets con distintos código que se utilizan en los archivos de configuración #webpack
This file contains 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
/** | |
* Utilizado para definir cual es el script que se utilizará para cada | |
* de las distintas etapas. | |
*/ | |
const TARGET = process.env.npm_lifecycle_event; | |
if (TARGET === 'dev') { | |
module.exports = require('./path-to/webpack.config.dev.js'); | |
} | |
if (TARGET === 'build') { | |
module.exports = require('./path-to/webpack.config.prod.js'); | |
} |
This file contains 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
/** | |
* Utlizado para un típico proyecto web | |
*/ | |
const HtmlWebpackPlugin = require('html-webpack-plugin') | |
const MiniCssExtractPlugin = require('mini-css-extract-plugin') | |
module.exports = { | |
// Javascript bundle | |
entry: `${__dirname}/src/main.js`, | |
output: { | |
path: `${__dirname}/dist`, | |
filename: `bundle.js` | |
}, | |
// Dev Server | |
devServer: { | |
port: 5000 | |
}, | |
// Loaders | |
module : { | |
rules: [ | |
{ | |
test: /\.css$/, | |
use: [ | |
{loader: MiniCssExtractPlugin.loader}, | |
{loader: 'css-loader'}, | |
{loader: 'sass-loader'} | |
] | |
} | |
] | |
}, | |
// Plugins | |
plugins: [ | |
// Plugin - HTML to dist | |
new HtmlWebpackPlugin({ | |
template: `./src/index.html` | |
}), | |
// Extrae el CSS en producción | |
new MiniCssExtractPlugin({ | |
filename: 'bundle.css' | |
}) | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment