-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.development.js
100 lines (92 loc) · 2.91 KB
/
webpack.config.development.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
const webpack = require('webpack');
// Module to provide plugins by default, in this case BrowserSyncPlugin
// or CleanWebpackPlugin (valid for jQuery too, see previous version)
const path = require('path');
// Module path require to define entry and out point, and the public folder
const HtmlWebpackPlugin = require('html-webpack-plugin')
// Plugin to inject an HTML template in develop and production mode
const CleanWebpackPlugin = require('clean-webpack-plugin')
// Cleans up the files inside dist folder are not gonna be used
const ExtractTextPlugin = require('extract-text-webpack-plugin');
// Plugin to create a bundle css apart of javascript
const port = process.env.PORT || 3000;
module.exports = {
// Development Mode [is] optimized for speed and developer experience
mode: 'development',
// Entry point to compile and create bundle
entry: `${path.resolve(__dirname, 'src')}/js/index.js`,
// Outpoint to compile in bundle.js all the files
output: {
path: path.join(__dirname, 'dist'),
// Path to output
filename: 'bundle.[hash].js',
// This is the result, bundle.[hash].js
// [hash] is a portion of the filename that will be replaced every time
// you bundle => helps with caching
publicPath: '/',
// Where the files are available in the server
},
devtool: 'inline-source-map',
// Tool to map Sass and javascript
devServer: {
contentBase: path.join(__dirname, 'dist'),
host: 'localhost',
port: port,
compress: true,
historyApiFallback: true,
open: true,
stats: 'errors-only',
hot: true
},
// Webpack Server
module: {
rules: [
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader'],
}),
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{ loader: 'css-loader', options: { sourceMap: true } },
{ loader: 'postcss-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: { sourceMap: true } },
],
}),
},
{
test: /\.js$/,
include: path.resolve(__dirname, 'src'),
exclude: /(node_modules)/,
loader: 'babel-loader',
},
{
test: /\.(png|jpe?g|gif|svg)(\?[\s\S]+)?$/,
use: [
{
loader: 'file-loader',
options: {}
}
]
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './public/index.html',
favicon: './public/favicon.ico'
}),
new CleanWebpackPlugin(['dist/static/', 'dist/styles/', 'dist/*.html', 'dist/favicon.ico', 'dist/images/']),
new webpack.HotModuleReplacementPlugin(),
new ExtractTextPlugin({
filename: 'styles/styles.[hash].css',
allChunks: true,
disable: process.env.NODE_ENV !== 'production'
})
]
}