-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
84 lines (77 loc) · 2.64 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
/* eslint-env node */
import webpack from 'webpack';
import TerserPlugin from 'terser-webpack-plugin';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
import ReactRefreshWebpackPlugin from '@pmmmwh/react-refresh-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import path from 'path';
const isProductionBuild = process.env.NODE_ENV === 'production';
const STYLE_NAME = 'application-[hash].css';
const SCRIPT_NAME = 'application-[hash].js';
const PAGE_TITLE = 'THX Deep Note';
const config = {
mode: isProductionBuild ? 'production' : 'development',
entry: './src/index.ts',
output: {
path: path.resolve((isProductionBuild ? './dist' : './build')),
filename: SCRIPT_NAME
},
module: {
rules: [
{ test: /\.tsx?$/, use: [{ loader: 'ts-loader' }], exclude: /(node_modules)/ },
{ test: /\.(png|jpg)$/, loader: 'url-loader', options: {limit: 8192} },
{ test: /\.s(a|c)ss$/, enforce: 'pre', use: ['sass-loader'] },
]
},
plugins: [
new webpack.DefinePlugin({
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development')
}),
new HtmlWebpackPlugin({title: PAGE_TITLE, template: './src/index.html'})
],
resolve: {
extensions: ['.js', '.ts', '.jsx', '.tsx', '.module.scss', '.scss'],
modules: [
'./node_modules',
'./src'
]
}
};
if (isProductionBuild) {
config.plugins.push(
new MiniCssExtractPlugin({
filename: STYLE_NAME,
})
);
config.output.publicPath = '/apps/gap-analysis-project/assets/';
config.module.rules.push(
{ test: /\.module\.(css|sass|scss)$/, use: [MiniCssExtractPlugin.loader, { loader: 'css-loader', options: { modules: { localIdentName: '[hash:base64]' }}} ] },
{ test: /\.(css|sass|scss)$/, exclude: /\.module\.(css|sass|scss)$/, use: [MiniCssExtractPlugin.loader, { loader: 'css-loader'} ] }
);
config.optimization = {
minimize: true,
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin()
],
};
} else {
config.devtool = 'eval-source-map';
config.devServer = {
port: 7879,
host: '0.0.0.0',
headers: {
'Access-Control-Allow-Origin': '*'
}
};
config.output.publicPath = 'http://localhost:7879/';
config.module.rules.push(
{ test: /\.module\.(css|sass|scss)$/, use: ['style-loader', { loader: 'css-loader', options: { modules: { localIdentName: '[local]__[hash:base64]' }}} ] },
{ test: /\.(css|sass|scss)$/, exclude: /\.module\.(css|sass|scss)$/, use: ['style-loader', { loader: 'css-loader' } ] },
);
config.plugins.push(
new ReactRefreshWebpackPlugin()
);
}
export default config;