-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.client.babel.js
154 lines (152 loc) · 4.54 KB
/
webpack.config.client.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import path from 'path'
import webpack from 'webpack'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import CleanFolder from 'clean-webpack-plugin'
import OptmizeCSS from 'optimize-css-assets-webpack-plugin'
import UglifyJsPlugin from 'uglifyjs-webpack-plugin'
import CopyFiles from 'copy-webpack-plugin'
const distPath = 'deploy'
const environment = process.env.NODE_ENV ? process.env.NODE_ENV.trim() : 'development'
export default {
module: {
rules: [
{
test: /\.jsx?$/, // regex to find files that webpack applies
resolve: {
extensions: ['.js', '.jsx', '.styl'], // resolves files extensiosn
},
exclude: /node_modules/, // avoiding node_module folders
use: {
loader: 'babel-loader', // using babel loader for transpiling es6 to es5
options: {
cacheDirectory: true, // option to transpile only modfied files
},
},
},
{
test: /\.scss/,
resolve: {
extensions: ['.scss'],
},
exclude: /node_modules/,
use: [
{
loader: 'style-loader',
},
{
loader: MiniCssExtractPlugin.loader,
options: {
// you can specify a publicPath here
// by default it use publicPath in webpackOptions.output
publicPath: path.resolve(__dirname, `/${distPath}/css`),
},
},
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
// you can specify a publicPath here
// by default it use publicPath in webpackOptions.output
publicPath: `./${distPath}/css`,
},
},
'css-loader',
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/',
publicPath: '../fonts/',
},
},
],
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'img/',
publicPath: '/static/img',
},
},
],
},
],
},
performance: {
hints: false,
},
devtool:
environment === 'development'
? 'source-map'
: 'false' /* testing if it's in development mode or production (to generate soucermap file for minified js file) */,
optimization: {
minimizer:
environment === 'production'
? [
new UglifyJsPlugin({
test: /\.js(\?.*)?$/i,
cache: true,
parallel: true,
sourceMap: environment !== 'production',
uglifyOptions: {
output: {
comments: false,
},
},
}),
new OptmizeCSS({}),
]
: [],
},
entry: './src/client.js', // main file to generates the bundle
output: {
// output settings
path: path.resolve(__dirname, `${distPath}`), // it defines its output folder
filename: 'js/bundle.js', // bundle name
publicPath: '/',
},
plugins: [
// define plugins used by webpack and its properties/settings
new CleanFolder([`${distPath}/*`], { root: __dirname }),
// htmlPlugin,
new webpack.DefinePlugin({
'process.env': {
VARIABLE: JSON.stringify('testando'), // sending process.env varible called VARIABLE with 'testando' value
},
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: 'css/bundle.css',
chunkFilename: 'css/chunk.css',
}),
],
devServer: {
// webpack dev server settings
contentBase: path.join(__dirname, distPath), // point to the path to run on server
compress: true, // it defines if it should be compressed
watchContentBase: true, // watch changes on file and re-run the application
port: 3000, // port
historyApiFallback: true, // it's used to fix router problemas with react-router and index.html defaull fallback https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback
writeToDisk: true, // Tells devServer to write generated assets to the disk.
},
}