Skip to content

Instantly share code, notes, and snippets.

@sibelius
Created February 5, 2020 15:33
Show Gist options
  • Save sibelius/95c9ec1ec17f31d75843542e31493e14 to your computer and use it in GitHub Desktop.
Save sibelius/95c9ec1ec17f31d75843542e31493e14 to your computer and use it in GitHub Desktop.
current webpack config
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const dotEnv = require('dotenv-webpack');
const HappyPack = require('happypack');
const Serve = require('webpack-plugin-serve');
const workboxPlugin = require('workbox-webpack-plugin');
const PORT = process.env.PORT;
const cwd = process.cwd();
const outputPath = path.join(cwd, 'build');
const srcPath = path.join(cwd, 'src');
module.exports = {
mode: 'development',
context: path.resolve(cwd, './'),
entry: ['react-hot-loader/patch', './src/index.tsx', 'webpack-plugin-serve/client'],
devtool: 'cheap-eval-source-map',
output: {
path: outputPath,
filename: 'bundle.js',
publicPath: '/',
pathinfo: false,
// https://github.com/webpack/webpack/pull/8642
futureEmitAssets: true,
},
resolve: {
modules: [srcPath, 'node_modules'],
extensions: ['.ts', '.tsx', '.js', '.json', '.mjs'],
},
module: {
rules: [
{
test: /\.mjs$/,
include: /node_modules/,
type: 'javascript/auto',
},
{
test: /\.(js|jsx|ts|tsx)?$/,
exclude: [/node_modules/],
use: 'happypack/loader?id=js',
include: [srcPath, path.join(cwd, '../')],
},
{
test: /\.(jpe?g|png|gif|svg|pdf|csv|xlsx|ttf|woff(2)?)$/i,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'img/',
},
},
],
},
{
test: /\.css$/,
use: 'happypack/loader?id=styles',
},
],
},
watch: true,
plugins: [
new Serve.WebpackPluginServe({
port: PORT,
historyFallback: {
disableDotRule: true,
verbose: true,
rewrites: [
{
from: '/wps',
to: context => context.parsedUrl.pathname,
},
{
from: /.js/,
to: context => context.parsedUrl.pathname,
},
],
},
static: [outputPath],
status: false,
}),
new dotEnv({
path: './.env',
}),
new HappyPack({
id: 'js',
threads: 4,
loaders: ['babel-loader?cacheDirectory'],
}),
new HappyPack({
id: 'styles',
threads: 2,
loaders: ['style-loader', 'css-loader'],
}),
new HtmlWebpackPlugin({
template: './src/index.html',
chunksSortMode: 'none',
}),
new workboxPlugin.InjectManifest({
swSrc: path.join(cwd, './src/sw.js'),
swDest: 'home/sw.js',
}),
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment