-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.prod.babel.js
170 lines (161 loc) · 4.74 KB
/
webpack.config.prod.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import path from 'path';
import webpack from 'webpack';
import cssnext from 'postcss-cssnext';
import BundleTracker from 'webpack-bundle-tracker';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import WebpackMd5Hash from 'webpack-md5-hash';
// eslint-disable-next-line import/no-unresolved
import * as ReactManifest from './frontend/dist/dll/react_manifest.json';
export default {
// The base directory, an absolute path, for resolving entry points and loaders from configuration
context: path.resolve(__dirname),
// Start entry point(s)
entry: {
app: [
'./frontend/src/index',
],
},
// Affecting the output of the compilation
output: {
// path: the output directory as an absolute path (required)
path: path.resolve(__dirname, 'frontend/dist/prod'),
// filename: specifies the name of output file on disk (required)
// Use hash string to handle client side cache problem
filename: '[name]-[chunkhash:10].js',
},
// Determine how the different types of modules within a project will be treated
module: {
rules: [
// Use awesome-typescript-loader and babel-loader for ts(x) files
{
test: /\.tsx?$/,
include: path.resolve(__dirname, 'frontend/src/'),
use: [
{
loader: 'babel-loader',
},
{
loader: 'awesome-typescript-loader',
options: {
// Use those two flags to speed up babel compilation
// https://github.com/s-panferov/awesome-typescript-loader#differences-between-ts-loader
useBabel: true,
useCache: true,
},
},
// Alternatively, we can use ts-loader instead of awesome-typescript-loader
// {
// loader: 'ts-loader',
// },
],
},
// Use ExtractTextPlugin and list of loaders to load and compile scss files to css files
{
test: /\.scss$/,
include: path.resolve(__dirname, 'frontend/src/'),
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
'css-loader',
'postcss-loader',
'sass-loader',
],
}),
},
// Use file-loader and image-loader to load images
{
test: /\.(png|jpe?g|gif|svg)$/,
include: path.resolve(__dirname, 'frontend/src/'),
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
},
},
{
loader: 'image-webpack-loader',
options: {
bypassOnDebug: true,
},
},
],
},
// Use file-loader to load font related files and icon
{
test: /\.(eot|woff2?|ttf|ico)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
],
},
],
},
// A list of used webpack plugins
plugins: [
// Minimize javascript files with source map generated
new webpack.optimize.UglifyJsPlugin({
output: { comments: false },
sourceMap: true,
}),
// Use cssnext in postcss when loading scss
new webpack.LoaderOptionsPlugin({
test: /\.scss$/,
options: {
postcss: {
plugins: [cssnext],
},
},
}),
// Define production env which shaved off 75% of the build output size
// http://moduscreate.com/optimizing-react-es6-webpack-production-build
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
}),
// jQuery support
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
'root.jQuery': 'jquery',
}),
// Load pre-build react dll reference files
new webpack.DllReferencePlugin({
manifest: ReactManifest,
context: __dirname,
}),
// Output webpack compiled bundle state json file for django backend
new BundleTracker({ filename: './webpack-stats.prod.json' }),
// Extract css part from javascript bundle into a file
new ExtractTextPlugin('[name]-[contenthash:10].css'),
// Better hash for [hash] and [chunkhash]
new WebpackMd5Hash(),
],
// Change how modules are resolved
resolve: {
// What directories should be searched when resolving modules
modules: [
'node_modules',
'frontend/src',
'frontend/materialize',
],
// Automatically resolve certain extensions (Ex. import 'folder/name(.ext)')
extensions: [
'.ts',
'.tsx',
'.js',
'.jsx',
'.json',
'.scss',
],
},
// Source map mode
// https://webpack.js.org/configuration/devtool
devtool: 'source-map',
};