-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.prod.config.js
More file actions
143 lines (127 loc) · 3.32 KB
/
Copy pathwebpack.prod.config.js
File metadata and controls
143 lines (127 loc) · 3.32 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
"use strict";
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var CleanWebpackPlugin = require('clean-webpack-plugin');
var path = require("path");
var webpack = require("webpack");
var Uglify = require("uglifyjs-webpack-plugin");
var BUILD_DIR = path.resolve(__dirname, "build/");
var APP_DIR = path.resolve(__dirname, "src/");
var appEntry = [
APP_DIR + "/styles/global.scss",
// scss files
APP_DIR + "/scripts/index.jsx"
// js files
];
// 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: "nosources-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,
minimize: 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 Uglify(),
new CleanWebpackPlugin(['build'], { verbose: true }),
// clean build directory
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"
}),
],
resolve: {
extensions: [".js", ".json", ".jsx", ".ts", ".tsx"],
alias: {
resources: path.resolve(APP_DIR, "resources")
}
}
};
module.exports = config;