-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.dev.js
149 lines (142 loc) · 4.89 KB
/
webpack.dev.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
const path = require('path');
const { merge } = require('webpack-merge');
const common = require('./webpack.common.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
const DotenvPlugin = require('dotenv-webpack');
const Dotenv = require('dotenv');
const fs = require('fs');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const dotEnvFile = fs.existsSync('.env.development.local') ? './.env.development.local' : './env/env-template';
Dotenv.config({
path: dotEnvFile,
});
const socialMediaPicture = process.env.SOCIAL_MEDIA_PICTURE;
const PUBLIC_URL = process.env.PUBLIC_URL;
module.exports = merge(common, {
devtool: 'cheap-module-source-map',
mode: 'development',
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].js',
// for webpack-dev-server only !
publicPath: '/public/build/',
},
//context: path.resolve(__dirname),
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader', // For polyfilling
options: {
cacheDirectory: false,
// plugins: ['react-hot-loader/babel'], in babelrc
},
},
{
loader: 'ts-loader',
options: {
configFile: 'tsconfig.dev.json',
transpileOnly: true,
},
},
],
},
{
test: /\.(s?css)$/,
use: ['css-hot-loader', 'style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
use: [
{
loader: 'file-loader',
options: {
name: 'images/[name]-[hash].[ext]',
},
},
],
},
{
test: /\.woff$|\.woff2?$/,
loader: 'file-loader',
//use: 'url-loader?limit=10000',
options: {
limit: 50000,
mimetype: 'application/font-woff',
name: 'fonts/[name].[ext]',
},
},
],
},
plugins: [
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: 'tsconfig.dev.json',
},
}),
new DotenvPlugin({
path: dotEnvFile, // load this now instead of the ones in '.env'
safe: true, // load '.env.example' to verify the '.env' variables are all set. Can also be a string to a different file.
systemvars: true, // load all the predefined 'process.env' variables which will trump anything local per dotenv specs.
silent: false, // hide any errors
}),
/*
new BundleAnalyzerPlugin({
analyzerMode: 'static'
})
*/
new HtmlWebpackPlugin({
alwaysWriteToDisk: true,
hash: false,
template: './public/index.html',
templateParameters: {
socialMediaPicture: socialMediaPicture,
publicUrl: PUBLIC_URL,
title: "Steve Paxton's Material for the spine",
},
removeAttributeQuotes: false,
removeComments: false,
minify: {
collapseWhitespace: false,
collapseInlineTagWhitespace: false,
},
}),
new HtmlWebpackHarddiskPlugin(),
],
optimization: {
namedModules: true, // NamedModulesPlugin()
},
devServer: {
contentBase: path.resolve(__dirname, 'build'),
port: 3001,
hot: true,
// to allow devserver to be accessed from multiple
// machines. Be aware it's a security risk too
disableHostCheck: true,
host: '0.0.0.0',
historyApiFallback: {
rewrites: [
{ from: /^\/$/, to: 'index.html' },
{ from: /page\//, to: 'index.html' },
{ from: /welcome\//, to: 'index.html' },
{ from: /menu\//, to: 'index.html' },
],
},
inline: true,
proxy: {
'/api': {
changeOrigin: true,
target: 'http://mfts.local/',
},
},
headers: {
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
'Access-Control-Allow-Origin': '*',
},
},
});