Last active
January 1, 2018 14:30
-
-
Save YonatanKra/3369510d552daade71e4f083d36dbc78 to your computer and use it in GitHub Desktop.
Splitting the config files for production and development
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
const path = require('path'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const webpack = require('webpack'); | |
module.exports = { | |
entry: ['./src/app.js'], // this is our app | |
output: { | |
chunkFilename: '[name].bundle.js', | |
filename: '[name].bundle.js', // the file name would be my entry's name with a ".bundle.js" suffix | |
path: path.resolve(__dirname, 'dist') // put all of the build in a dist folder | |
}, | |
plugins: [ | |
// This plugin creates our index.html that would load the app for us in the browser | |
new HtmlWebpackPlugin({ | |
title: 'Your Phrase Fireworks!' | |
}), | |
new webpack.ProvidePlugin({ | |
jQuery: 'jquery', | |
$: 'jquery', | |
jquery: 'jquery' | |
}), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: "vendor", | |
minChunks: function (module) { | |
return module.context && | |
module.context.includes("node_modules"); | |
} | |
}), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: "manifest", | |
minChunks: Infinity | |
}) | |
], | |
module: { | |
rules: [ | |
// use the url loader for font files | |
{ | |
test: /\.(woff2?|ttf|eot|svg)$/, | |
use: [ | |
{ | |
loader: 'url-loader', | |
options: { | |
limit: 10000 | |
} | |
} | |
] | |
}, | |
// use the html loader | |
{ | |
test: /\.html$/, | |
exclude: /node_modules/, | |
use: [{loader: 'html-loader'}] | |
}, | |
// use the css loaders (first load the css, then inject the style) | |
{ | |
test: /\.css$/, | |
use: [ | |
'style-loader', | |
'css-loader' | |
] | |
} | |
] | |
} | |
}; |
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
const merge = require('webpack-merge'); | |
const commonConfig = require('./webpack.common'); | |
module.exports = merge(commonConfig, { | |
devtool: 'inline-source-map', | |
devServer: { | |
open: true, | |
contentBase: './dist' | |
}, | |
}); |
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
const UglifyJsPlugin = require('uglifyjs-webpack-plugin'); | |
const CleanWebpackPlugin = require('clean-webpack-plugin'); | |
const merge = require('webpack-merge'); // don't forget to install this one | |
const commonConfig = require('./webpack.common'); | |
module.exports = merge(commonConfig, { | |
devtool: 'source-map', | |
plugins: [ | |
new CleanWebpackPlugin(['dist']), | |
new UglifyJsPlugin({ | |
sourceMap: true | |
}) | |
] | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment