39
loading...
This website collects cookies to deliver better user experience
├── dist
├── index.ts
├── package.json
├── tsconfig.json
└── yarn.lock
yarn add -D webpack webpack-cli
yarn add -D esbuild-loader fork-ts-checker-webpack-plugin nodemon-webpack-plugin
// External modules
const path = require('path');
// Webpack plugins
const NodemonPlugin = require('nodemon-webpack-plugin');
const ForkTsCheckerPlugin = require('fork-ts-checker-webpack-plugin');
// Environment config
const isDevelopment = process.env.NODE_ENV !== 'production';
const mode = isDevelopment ? 'development' : 'production';
// Bundle config options
const BUNDLE = {
entry: './index.ts',
output: {
filename: 'app.js',
path: path.resolve(__dirname, 'dist')
}
};
module.exports = {
mode,
target: 'node',
entry: BUNDLE.entry,
stats: 'errors-only',
module: getLoaders(),
plugins: getPlugins(),
resolve: {
extensions: ['.tsx', '.ts', '.js', '.json']
},
output: BUNDLE.output
};
/**
* Loaders used by the application.
*/
function getLoaders() {
const esbuild = {
test: /\.(js|jsx|ts|tsx)?$/,
loader: 'esbuild-loader',
options: {
loader: 'tsx',
target: 'es2015'
},
exclude: /node_modules/
};
const loaders = {
rules: [esbuild]
};
return loaders;
}
/**
* Plugins
*/
function getPlugins() {
const nodemon = new NodemonPlugin();
const tsChecker = new ForkTsCheckerPlugin();
return [tsChecker, nodemon];
}
scripts
to our package.json. During development we'll take advantage of Webpack's Hot Module Replacement with the --hot
flag"start": "yarn build --watch --hot",
"build": "webpack --color --progress"
yarn start
node_modules
from your bundle