Skip to content

Instantly share code, notes, and snippets.

@phoenisx
Created June 12, 2017 16:00
Show Gist options
  • Save phoenisx/0ce81ed4eb76f08713220671da88e696 to your computer and use it in GitHub Desktop.
Save phoenisx/0ce81ed4eb76f08713220671da88e696 to your computer and use it in GitHub Desktop.
Basic set- up for Webpack Config with Proxy and Plugins
var webpack = require('webpack');
var path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const config = require('./config')
const extractText = new ExtractTextPlugin({
filename: "[name].css"
})
var webpackConfig = {
devtool: 'source-map',
devServer: {
compress: true,
port: 9000,
hot: true,
historyApiFallback: true,
headers: {
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, PATCH, OPTIONS",
"Access-Control-Allow-Headers": "X-Requested-With, Content-Type, Authorization",
"Access-Control-Allow-Origin": "*",
},
proxy: {
'/api/**/*.json': {
target: "http://localhost:8080",
changeOrigin: true,
pathRewrite: {
"^/api": ""
},
logLevel: 'debug',
}
}
},
entry: {
index: './src/routes.jsx'
},
resolve: {
modules: ['node_modules', 'src'],
extensions: ['.js', '.jsx', '.scss']
},
}
webpackConfig.output = {
path: path.join(__dirname, 'dist'),
filename: '[name].js',
};
webpackConfig.module = {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'react-hot-loader'
},
{
loader: 'babel-loader',
options: {
presets: ['react' , 'es2015'],
plugins: ["transform-object-rest-spread"]
}
}
]
},
{
test: /\.scss$/,
use: extractText.extract({
use: [
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
plugins: (loader) => [
require('autoprefixer')()
]
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true
}
}
],
fallback: "style-loader"
})
},
{
test: /\.(hbs|handlebars)$/,
use: [
{
loader: 'handlebars-loader'
}
]
},
{
test: /\.(jpg|png|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
}
}
]
}
]
};
webpackConfig.plugins = [
new webpack.ProvidePlugin({
mapboxgl: 'mapbox-gl',
turf: "@turf/turf"
}),
extractText,
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
title: 'Some Title',
filename: 'index.html',
template: 'src/template.hbs'
})
]
module.exports = webpackConfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment