Skip to content

Instantly share code, notes, and snippets.

@iamitshri
Created July 12, 2017 21:06
Show Gist options
  • Save iamitshri/8f1f6c4f719c62792df8cbd4fcfdc364 to your computer and use it in GitHub Desktop.
Save iamitshri/8f1f6c4f719c62792df8cbd4fcfdc364 to your computer and use it in GitHub Desktop.
Webpack snippet to help bundle Bootstrap, jquery and JS files
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
module.exports = {
context: __dirname + "/webapp",
entry: {
advancedSearch: [
'./js/advancedSearch.js'
]
},
output: {
path: path.resolve(__dirname, './webapp/react-dist'),
filename: '[name]-webpack-bundle.js',
},
watch: false,
devtool:"cheap-module-source-map",
devServer: {
contentBase: __dirname
},
module: {
rules: [{
test: /.js$/,
loader: 'babel-loader',
exclude: /node_modules/,
options: {
presets: ['es2015', 'react']
}
},
{
test: /\.png$/,
loader: "url-loader",
options: { limit: 100000 }
},
{
test: /\.jpg$/,
loader: "file-loader"
},
{
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
options: { limit: 100000, mimetype: 'application/font-woff' }
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
options: { limit: 100000, mimetype: 'application/octet-stream' }
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader',
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
options: { limit: 100000, mimetype: 'image/svg+xml' }
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
},
]
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery'
}),
new ExtractTextPlugin({
filename: "[name].css"
}),
// Fixes warning in moment-with-locales.min.js
// Module not found: Error: Can't resolve './locale' in ...
new webpack.IgnorePlugin(/\.\/locale$/)
],
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment