-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathwebpack.config.js
137 lines (129 loc) · 3.67 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
130
131
132
133
134
135
136
137
const autoprefixer = require('autoprefixer');
const env = process.env.NODE_ENV;
const path = require( 'path' );
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
module.exports = {
mode: 'development',
entry: [
require.resolve('./src/polyfills'),
'./src/index.js'
],
output: {
path: path.resolve( __dirname, 'build' ),
filename: 'static/js/[name].[chunkhash:8].js',
pathinfo: process.env.NODE_ENV === 'development',
},
resolve: {
modules: [
path.join(__dirname, "src"),
"node_modules"
],
},
module: {
rules: [
{
exclude: [
/\.(eot|ttf|woff|woff2)$/,
/\.html$/,
/\.(js|jsx)$/,
/\.css$/,
/\.json$/,
/\.svg$/,
],
loader: 'url-loader',
query: {
limit: 10000,
name: 'static/media/[name].[hash:8].[ext]'
}
},
{
test: /\.(js|jsx)$/,
include: /src/,
loader: 'babel-loader',
},
{
test: /\.css$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: process.env.NODE_ENV === 'development',
},
},
{
loader: 'css-loader',
options: {
importLoaders: 1
}
},
{
loader: 'postcss-loader',
// We use PostCSS for autoprefixing only.
options: {
plugins: function() {
return [ autoprefixer() ];
}
},
}
]
},
// Web workers.
{
test: /\.worker\.(js|jsx)$/,
include: /src/,
exclude: /node_modules/,
use: [
{ loader: 'worker-loader' },
{ loader: 'babel-loader'}
],
},
// "file" loader for fonts and svg
{
include: [
/\.(eot|ttf|woff|woff2)$/,
/\.svg$/,
],
loader: 'file-loader',
query: {
name: 'static/media/[name].[hash:8].[ext]'
}
}
]
},
plugins: [
new MiniCssExtractPlugin( {
// need to be placed in root, because references other media items like fonts
filename: '[name].css',
} ),
// Generates an `index.html` file with the <script> injected.
new HtmlWebpackPlugin({
filename: 'index.html',
template: './src/index.html',
}),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
new webpack.DefinePlugin(env),
// If you require a missing module and then `npm install` it, you still have
// to restart the development server for Webpack to discover it. This plugin
// makes the discovery automatic so you don't have to restart.
// See https://github.com/facebookincubator/create-react-app/issues/186
new WatchMissingNodeModulesPlugin('node_modules'),
// Generate a manifest file which contains a mapping of all asset filenames
// to their corresponding output file so that tools can pick it up without
// having to parse `index.html`.
new ManifestPlugin({
fileName: 'asset-manifest.json'
})
],
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};