-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.frontend.babel.js
125 lines (120 loc) · 4.11 KB
/
webpack.config.frontend.babel.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import AddAssetHtmlPlugin from 'add-asset-html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import DuplicatePackageCheckerPlugin from "duplicate-package-checker-webpack-plugin";
import ProgressBarWebpackPlugin from "progress-bar-webpack-plugin";
import { DllReferencePlugin } from "webpack";
import cssnano from "cssnano";
import MiniCssExtractPlugin from "mini-css-extract-plugin";
import postcssImport from "postcss-import";
import postcssPresetEnv from "postcss-preset-env";
const ReactManifest = './frontend/dist/dll/react_manifest.json';
const devMode = process.env.NODE_ENV !== 'production';
export default {
context: path.resolve(__dirname),
mode: process.env.NODE_ENV || 'development',
target: "web",
entry: './frontend/src/index.tsx',
output: {
path: path.resolve(__dirname, 'frontend/dist'),
filename: '[name].[hash:10].js',
chunkFilename: '[name].[hash:10].js',
},
resolve: {
extensions: [ '.ts', '.tsx', ".js", ".json"]
},
module: {
rules: [
{
test: /\.tsx?$/,
use: [
{ loader: 'babel-loader' },
{
loader: 'awesome-typescript-loader',
options: {
useBabel: true,
useCache: true,
silent: true,
}
}
]
},
{
test: /\.css$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: !devMode,
importLoaders: 1,
},
}, // TODO: enable sourceMap in devMode without FOUC
{
loader: 'postcss-loader',
options: {
sourceMap: true,
plugins: () => [postcssImport, postcssPresetEnv, cssnano],
},
},
],
},
{
test: /\.(png|jpe?g|gif|svg|webp|tiff)(\?.*)?$/,
use: [
{ loader: 'url-loader', options: { limit: 10000, name: '[name].[hash:7].[ext]' } },
{ loader: 'image-webpack-loader', options: { disable: devMode } },
],
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}]
},
]
},
devServer: {
// Port number for webpack dev server
port: 3004,
// Add proxy for api call
proxy: {
'/api': {
target: 'http://localhost:3000/',
secure: false,
changeOrigin: true,
},
},
// Automatically open page
open: true,
historyApiFallback: true,
},
devtool: 'inline-source-map',
plugins: [
new ProgressBarWebpackPlugin(),
new DuplicatePackageCheckerPlugin(),
new DllReferencePlugin({ manifest: ReactManifest }),
// Generate html file to dist folder
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'frontend/public/index.html')
}),
// Add dll reference files to html
new AddAssetHtmlPlugin({
filepath: path.resolve(__dirname, 'frontend/dist/dll/*_dll.js'),
includeSourcemap: false,
}),
// Copy static files to build dir
new CopyWebpackPlugin([
{
from: 'frontend/public/**/*',
to: '[name].[ext]',
ignore: ['index.html'],
},
]),
]
}