-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.common.js
More file actions
116 lines (114 loc) · 3.2 KB
/
webpack.common.js
File metadata and controls
116 lines (114 loc) · 3.2 KB
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
const CopyWebpackPlugin = require('copy-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const HtmlWebPackPlugin = require('html-webpack-plugin')
const ErrorOverlayPlugin = require('error-overlay-webpack-plugin')
const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin')
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const path = require('path')
const webpack = require('webpack')
const ENV = require('./env')
const { PORT, NODE_ENV, ASSET_PATH } = ENV[process.env.NODE_ENV]
const isProd = NODE_ENV === 'production'
module.exports = {
entry: ['./src/app.tsx'],
output: {
filename: 'static/js/[name].[hash].chunk.js',
path: path.resolve('./dist'),
publicPath: ASSET_PATH,
},
module: {
rules: [
{
test: /\.s?css$/,
oneOf: [
{
test: /\.module\.s?css$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
modules: {
mode: 'local',
localIdentName: 'style_[local]__[hash:base64:5]',
context: path.resolve(__dirname, 'src'),
hashPrefix: 'my-custom-hash',
},
onlyLocals: false,
},
},
'sass-loader',
],
},
{
use: [MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader'],
},
],
},
{
oneOf: [
{
test: /\.css$/,
include: /node_modules/,
use: ['style-loader', 'css-loader'],
sideEffects: isProd,
},
],
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
},
},
],
},
{
test: /\.(t|j)sx?$/,
loader: 'awesome-typescript-loader',
},
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader',
},
],
},
resolve: {
alias: {
'react-dom': '@hot-loader/react-dom',
styles: path.resolve('./src/styles'),
},
extensions: ['.ts', '.tsx', '.js', '.jsx'],
},
devtool: 'source-map',
plugins: [
new SimpleProgressWebpackPlugin({ format: 'compact' }),
new FriendlyErrorsWebpackPlugin(),
new HtmlWebPackPlugin({
template: './public/index.html',
favicon: './public/resources/images/favicon.ico',
}),
new MiniCssExtractPlugin({
filename: isProd
? 'static/css/[name].[contenthash].chunk.css'
: '[name].css',
}),
new ErrorOverlayPlugin(),
new CleanWebpackPlugin(),
new webpack.HotModuleReplacementPlugin(),
new CopyWebpackPlugin([{ from: 'public/resources' }]),
new BrowserSyncPlugin({
host: 'localhost',
port: PORT,
proxy: 'http://localhost:8080/',
open: false,
}),
],
}