Skip to content

Instantly share code, notes, and snippets.

@AZagatti
Created July 23, 2020 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AZagatti/0ffb87bc4679aacffc8c13f6664f662e to your computer and use it in GitHub Desktop.
Save AZagatti/0ffb87bc4679aacffc8c13f6664f662e to your computer and use it in GitHub Desktop.
Webpack config
require('dotenv').config();
const Dotenv = require('dotenv-webpack');
import * as webpack from 'webpack';
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const htmlPlugin = new HtmlWebpackPlugin({
template: './public/index.html',
});
const config = {
mode: 'development',
entry: './index.tsx',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
plugins: [new TsconfigPathsPlugin({ configFile: './tsconfig.json' })],
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'awesome-typescript-loader',
},
{
test: /\.css/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
},
{
test: /.*\.(gif|png|jpe?g)$/i,
use: {
loader: 'file-loader',
},
},
],
},
devServer: {
historyApiFallback: true,
},
plugins: [htmlPlugin, new Dotenv()],
};
module.exports = config;
require('dotenv').config();
const Dotenv = require('dotenv-webpack');
const path = require('path');
import * as webpack from 'webpack';
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const htmlPlugin = new HtmlWebpackPlugin({
template: './public/index.html',
filename: './index.html',
});
const config: webpack.Configuration = {
mode: 'production',
entry: './index.tsx',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
plugins: [new TsconfigPathsPlugin({ configFile: './tsconfig.json' })],
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'awesome-typescript-loader',
},
{
test: /\.css/,
use: [{ loader: 'style-loader' }, { loader: 'css-loader' }],
},
{
test: /.*\.(gif|png|jpe?g)$/i,
use: {
loader: 'file-loader',
},
},
],
},
plugins: [htmlPlugin, new Dotenv()],
};
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment