-
-
Save jgcmarins/e4b964e641f1631b8533a1923b0c30f2 to your computer and use it in GitHub Desktop.
current webpack config
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 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