-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.dev.babel.js
193 lines (182 loc) · 5.59 KB
/
webpack.config.dev.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import path from 'path';
import webpack from 'webpack';
import cssnext from 'postcss-cssnext';
import BundleTracker from 'webpack-bundle-tracker';
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: [
// Important! 'react-hot-loader/patch' must goes first
// https://github.com/gaearon/redux-devtools/commit/64f58b7010a1b2a71ad16716eb37ac1031f93915#diff-efacb933fc2cf0fd7e8dacf55a958839
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:3003/',
'webpack/hot/only-dev-server',
'./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/dev'),
// filename: specifies the name of output file on disk (required)
filename: '[name].js',
// publicPath: specifies the public URL of the output resource directory (CDN)
// https://webpack.js.org/configuration/output/#output-publicpath
publicPath: 'http://localhost:3003/',
},
// 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 a list of loaders to load and compile scss files to css files
{
test: /\.scss$/,
include: path.resolve(__dirname, 'frontend/src/'),
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
},
],
},
// Use url-loader to load images in development
{
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]',
},
},
],
},
],
},
plugins: [
// Enable hot module reload, if have --hot parameter in npm script, then this line must be removed!
new webpack.HotModuleReplacementPlugin(),
// Better webpack module name display
new webpack.NamedModulesPlugin(),
// Use cssnext in postcss when loading scss
new webpack.LoaderOptionsPlugin({
test: /\.scss$/,
options: {
postcss: {
plugins: [cssnext],
},
},
}),
// 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.dev.json' }),
// 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',
],
},
// Webpack-dev-server config goes here
devServer: {
// Where the webpack dev server serve the static files, should be the same as output.path
contentBase: path.resolve(__dirname, 'frontend/dist/dev'),
// Enable hot reload
hot: true,
// Port number for webpack dev server
port: 3003,
// Allow CORS
// https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md#no-access-control-allow-origin-header-is-present-on-the-requested-resource
headers: {
'Access-Control-Allow-Origin': '*',
},
// The public URL of the output resource directory (CDN), should be the same as output.publicPath
publicPath: 'http://localhost:3003/',
},
// Disable webpack asset size limit performance warning
performance: {
hints: false,
},
// Source map mode
// https://webpack.js.org/configuration/devtool
devtool: 'eval-source-map',
};