Created
March 13, 2019 19:12
-
-
Save dmiller9911/dbd4e449cb42733f9e37c6c58fd420a9 to your computer and use it in GitHub Desktop.
React Webpack Config Starter
This file contains hidden or 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 { join, resolve } = require('path'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
const srcDir = resolve(__dirname, './src'); | |
const distDir = resolve(__dirname, './dist'); | |
const publicDir = resolve(__dirname, './public'); | |
const appIndexFile = join(publicDir, 'index.html'); | |
module.exports = (env = {}) => { | |
const isProduction = Boolean(env.prod); | |
return { | |
mode: isProduction ? 'production' : 'development', | |
devtool: isProduction ? 'source-map' : 'eval', | |
entry: join(srcDir, 'index.tsx'), | |
output: { | |
path: distDir, | |
publicPath: '/', | |
filename: Boolean(env.prod) ? '[name].[chunkhash].js' : '[name].js' | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.tsx?$/, | |
use: 'ts-loader' | |
} | |
] | |
}, | |
resolve: { | |
extensions: ['.ts', '.tsx', '.mjs', '.js'] | |
}, | |
plugins: [ | |
new CopyWebpackPlugin([ | |
{ | |
from: '**/*', | |
to: distDir, | |
context: publicDir, | |
ignore: [appIndexFile] | |
} | |
]), | |
new HtmlWebpackPlugin({ | |
template: appIndexFile | |
}) | |
], | |
devServer: { | |
https: true, | |
port: 8080, | |
publicPath: '/', | |
historyApiFallback: true, | |
stats: { | |
modules: false | |
} | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment