Skip to content

Instantly share code, notes, and snippets.

@demian85
Created August 23, 2018 13:42
Show Gist options
  • Save demian85/0a6b7397600da1348200e41b2e504b84 to your computer and use it in GitHub Desktop.
Save demian85/0a6b7397600da1348200e41b2e504b84 to your computer and use it in GitHub Desktop.
const path = require('path');
const webpack = require('webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const mode = process.env.NODE_ENV || 'production';
const devtool = mode === 'development' ? 'cheap-module-source-map' : 'source-map';
const serverBuild = {
mode,
devtool,
target: 'node',
entry: './src/server/',
output: {
path: path.resolve(__dirname, './build/server/'),
filename: 'index.js',
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json']
},
module: {
rules: [
{ test: /\.tsx?$/, loader: 'ts-loader' },
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
{ test: /\.json$/, loader: 'json-loader' },
]
}
};
const clientBuild = {
mode,
devtool,
target: 'web',
context: path.resolve(__dirname, './src/'),
entry: {
js: './client/index.tsx',
css: './client/main.scss'
},
output: {
path: path.resolve(__dirname, './build/client/'),
filename: 'bundle.js',
},
resolve: {
extensions: ['.ts', '.js', '.tsx', '.json', '.scss', '.css']
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: path.resolve(__dirname, 'node_modules/'),
loader: 'ts-loader',
},
{
enforce: "pre",
test: /\.js$/,
loader: 'source-map-loader',
},
{
test: /\.json$/,
loader: 'json-loader' ,
},
{
test: /\.(scss|sass|css)$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
includePaths: ['node_modules/bootstrap-sass/assets/stylesheets']
}
}
]
},
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}),
new CopyWebpackPlugin([
{
from: './client/images/',
to: 'images/',
},
]),
new MiniCssExtractPlugin({
filename: "main.css",
}),
],
};
module.exports = [clientBuild, serverBuild];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment