-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.config.js
101 lines (97 loc) · 2.98 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const HtmlWebPackPlugin = require("html-webpack-plugin");
const HtmlWebpackInjector = require('html-webpack-injector');
const Dotenv = require("dotenv-webpack");
const webpack = require("webpack");
const path = require("path");
module.exports = () => {
const isDevServer = process.env.WEBPACK_DEV_SERVER;
const env = process.env.NODE_ENV || "local";
const dotenv = require('dotenv').config({ path: `./.env.${env}` });
const envPlugin = new Dotenv({ path: `./.env.${env}`, systemvars: true });
const htmlPlugin = new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html",
favicon: "./src/assets/favicon.ico",
chunks: ["bundle", "index_head"],
});
const injectorPlugin = new HtmlWebpackInjector();
const inlineSourceMaps = new webpack.SourceMapDevToolPlugin({
filename: "[file].map",
fallbackModuleFilenameTemplate: '[absolute-resource-path]',
moduleFilenameTemplate: '[absolute-resource-path]'
});
return {
module: {
rules: [
{
test: /\.(tsx|ts|jsx|js)$/,
use: 'ts-loader',
exclude: /node_modules/,
},
{ test: /\.(sa|sc|c)ss$/,
use: [
{ loader: "style-loader" },
{ loader: "css-loader", options: { modules: true } },
{ loader: "sass-loader", options: {
implementation: require("sass"),
sassOptions: {
// Only thing this does is allow us to import variables without relative pathing
data: '@import "variables";',
includePaths: [path.resolve(__dirname, "src/assets")],
outputStyle: 'compressed',
sourceMap: true,
outFile: 'style.css'
},
}
},
],
},
{
test: /\.(eot|svg|ttf|woff|woff2|png)$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "./assets/fonts/",
publicPath: "/assets/fonts/",
},
},
],
},
],
},
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx', '.scss'],
modules: [ path.join(__dirname, './src'), 'node_modules' ],
},
entry: {
bundle: "./src/index.tsx",
index_head: "./src/services/htmlHead.service.ts",
},
output: {
path: path.join(__dirname, `/dist/${env}`),
filename: "[name]-[hash:5].js",
publicPath: "/",
},
optimization: {
usedExports: true,
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
},
},
stats: {
entrypoints: false,
children: false,
},
plugins: [envPlugin, htmlPlugin, injectorPlugin, inlineSourceMaps],
devServer: {
hot: true,
port: process.env.PORT || 9000,
contentBase: path.join(__dirname, "dist"),
historyApiFallback: true,
},
devtool: 'inline-source-map',
};
};