-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
173 lines (148 loc) · 4.09 KB
/
Copy pathwebpack.config.js
File metadata and controls
173 lines (148 loc) · 4.09 KB
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
"use strict";
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var CleanWebpackPlugin = require('clean-webpack-plugin');
var path = require("path");
var webpack = require("webpack");
var isDevelopmentMode = process.env.NODE_ENV === "development";
var BUILD_DIR = path.resolve(__dirname, "build/");
var APP_DIR = path.resolve(__dirname, "src/");
var appEntry = [
// js files
"react-hot-loader/patch",
// activate HMR for React
"webpack-dev-server/client?http://localhost:3000",
// bundle the client for webpack-dev-server
// and connect to the provided endpoint
"webpack/hot/only-dev-server",
// bundle the client for hot reloading
// only- means to only hot reload for successful updates
APP_DIR + "/styles/global.scss",
// scss files
APP_DIR + "/scripts/index.jsx",
];
// allows splitting vendor modules
function isExternal(module) {
var context = module.context;
if (typeof context !== 'string') {
return false;
}
// returns true if module's context includes node_modules
return context.indexOf('node_modules') !== -1;
}
var config = {
entry: {
app: appEntry
},
output: {
path: BUILD_DIR,
filename: "bundle.js",
publicPath: "/build/"
// necessary for HMR to know where to load the hot update chunks
},
devtool: "inline-source-map",
// enable source maps
module: {
rules: [
{
test: /\.tsx?$/,
loader: ["awesome-typescript-loader"],
include: APP_DIR,
exclude: /node_modules/
},
{
test: /\.jsx?/,
include: APP_DIR,
exclude: /node_modules/,
use: [
{
loader: "babel-loader",
options: {
presets: [
["es2015", { modules: false }],
// webpack understands the native import syntax, and uses it for tree shaking
// https://webpack.js.org/guides/hmr-react/#babel-config
"stage-2",
"react"
]
}
}
]
},
{
test: /\.s?css$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: "css-loader", // The css-loader interprets @import and url() like import/require() and will resolve them
options: {
sourceMap: true
}
},
{
loader: "sass-loader", // Loads a SASS/SCSS file and and compiles it to CSS
options: {
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
plugins: [
require('autoprefixer')
]
}
}
],
fallback: "style-loader" // Adds CSS to the DOM by injecting a <style> tag
// use style-loader when not extracting (for eg: in development)
})
},
{
test: /\.(png|jpg|gif)$/,
use: [
{
loader: 'file-loader',
options: {}
}
]
}
]
},
plugins: [
new CleanWebpackPlugin(['build'], { verbose: true }),
// clean build directory
new webpack.HotModuleReplacementPlugin(),
// enable HMR globally
new webpack.NamedModulesPlugin(),
// prints more readable module names in the browser console on HMR updates
new webpack.NoEmitOnErrorsPlugin(),
// do not emit compiled assets that include errors
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
filename: "vendor.bundle.js",
minChunks: function (module) {
return isExternal(module);
}
}),
// code splitting for vendor
new ExtractTextPlugin({
filename: "bundle.css",
disable: true
}),
],
devServer: {
host: "localhost",
port: 3000,
historyApiFallback: true,
// respond to 404s with index.html
hot: true
// enable HMR on the server
},
resolve: {
extensions: [".js", ".json", ".jsx", ".ts", ".tsx"],
alias: {
resources: path.resolve(APP_DIR, "resources")
}
}
};
module.exports = config;