Skip to content

Instantly share code, notes, and snippets.

@molavec
Last active March 7, 2019 15:16
Show Gist options
  • Save molavec/9aa156a791f677273a3a4f6079caa6a9 to your computer and use it in GitHub Desktop.
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
/**
* 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');
}
/**
* 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