-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
129 lines (125 loc) · 3.9 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
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
// We are using node's native package 'path'
// https://nodejs.org/api/path.html
const path = require('path');
const isDebug = !process.argv.includes('--release');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
var InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
// Constant with our paths
const paths = {
DIST: path.resolve(__dirname, 'dist'),
SRC: path.resolve(__dirname, 'src'),
PUBLIC: path.resolve(__dirname, 'public'),
};
// Webpack configuration
module.exports = {
//entry: path.join(paths.SRC, 'index.js'),
entry: {
client: ['babel-polyfill', path.join(paths.SRC, 'index.js')],
},
output: {
path: paths.DIST,
//filename: 'index.bundle.js',
filename: isDebug ? '[name].js' : '[name].[chunkhash:8].js',
chunkFilename: isDebug
? '[name].chunk.js'
: '[name].[chunkhash:8].chunk.js',
// Point sourcemap entries to original disk location (format as URL on Windows)
devtoolModuleFilenameTemplate: info =>
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
},
// Tell webpack to use html plugin
plugins: [
new HtmlWebpackPlugin({
inject: true,
template: path.join(paths.PUBLIC, 'index.html'),
favicon: 'public/favicon.ico',
manifest: 'public/manifist.json',
minify: {
minifyCSS: true,
},
}),
new ExtractTextPlugin('style.bundle.css'), // CSS will be extracted to this bundle file,
new InterpolateHtmlPlugin({
PUBLIC_URL: '/'
// You can pass any key-value pairs, this was just an example.
// WHATEVER: 42 will replace %WHATEVER% with 42 in index.html.
}),
],
// Loaders configuration
// We are telling webpack to use "babel-loader" for .js and .jsx files
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: [
'babel-loader',
],
},
// CSS loader for CSS files
// Files will get handled by css loader and then passed to the extract text plugin
// which will write it to the file we defined above
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
use: 'css-loader',
}),
},
// File loader for image assets -> ADDED IN THIS STEP
// We'll add only image extensions, but you can things like svgs, fonts and videos
{
test: /\.(png|jpg|gif)$/,
use: [
'file-loader',
],
},
// Compile Less to CSS
// https://github.com/webpack-contrib/less-loader
// Install dependencies before uncommenting: yarn add --dev less-loader less
{
test: /\.less$/,
loader: 'less-loader',
},
// Compile Sass to CSS
// https://github.com/webpack-contrib/sass-loader
// Install dependencies before uncommenting: yarn add --dev sass-loader node-sass
{
test: /\.(scss|sass)$/,
loader: 'sass-loader',
},
{
test: /\.svg$/,
loader: 'svg-url-loader',
options: {
name: '[hash:8].[ext]',
limit: 4096, // 4kb
},
},
{
test: /\.woff(2)?(\?v=\d+\.\d+\.\d+)?$/,
loader: "url-loader"
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: "file-loader"
},
],
},
// Enable importing JS files without specifying their's extenstion
//
// So we can write:
// import MyComponent from './my-component';
//
// Instead of:
// import MyComponent from './my-component.jsx';
resolve: {
extensions: ['.js', '.jsx'],
modules: ['node_modules', 'src'],
},
devtool: isDebug ? 'cheap-module-inline-source-map' : 'source-map',
};