-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
153 lines (139 loc) · 4.57 KB
/
webpack.common.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
var path = require("path");
var webpack = require("webpack");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var PreloadWebpackPlugin = require('preload-webpack-plugin');
var CopyWebpackPlugin = require("copy-webpack-plugin");
var CleanWebpackPlugin = require("clean-webpack-plugin");
module.exports = {
entry: {
app: "./src/index.tsx"
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "dist")
},
devtool: "source-map",
resolve: {
extensions: [".webpack.js", ".web.js", ".ts", ".tsx", ".js"],
alias: {
"package.json$": path.resolve(__dirname, "package.json")
}
},
node: {
// empty imports for z3em
fs: "empty",
path: "empty",
crypto: "empty",
// false for everything else
console: false,
global: false,
process: false,
Buffer: false,
setImmediate: false
},
module: {
rules: [
{
test: /\.tsx?$/,
use: "ts-loader"
},
{
test: /\.less$/,
use: ExtractTextPlugin.extract({
fallback: {
loader: "style-loader",
options: {
sourceMap: true
}
},
use: [
{
loader: "css-loader",
options: {
sourceMap: true,
importLoaders: 1 // https://github.com/webpack-contrib/css-loader#importloaders
}
},
{
loader: "postcss-loader",
options: {
sourceMap: true
}
},
{
loader: "less-loader",
options: {
sourceMap: true
}
}
]
})
},
{
test: /\.(png|svg|jpg|gif)$/,
use: {
loader: "file-loader",
query: {
name: "[name].[ext]",
useRelativePath: true
}
}
},
{
test: /manifest\.json$/,
use: {
loader: "file-loader",
query: {
name: "[name].[ext]"
}
}
},
{
test: /\.wasm$/,
use: {
loader: "file-loader",
query: {
// always include hash for WASM cache invalidation in IndexedDB
name: "[name].[hash].[ext]"
}
}
}
]
},
plugins: [
// https://webpack.js.org/guides/output-management/#cleaning-up-the-dist-folder
new CleanWebpackPlugin(['dist']),
// https://webpack.js.org/guides/code-splitting-libraries/#manifest-file
new webpack.optimize.CommonsChunkPlugin({
name: "vendor",
minChunks: function (module) {
// this assumes your vendor imports exist in the node_modules directory
return module.context && module.context.indexOf("node_modules") !== -1;
}
}),
//CommonChunksPlugin will now extract all the common modules from vendor and main bundles
new webpack.optimize.CommonsChunkPlugin({
name: "manifest" //But since there are no more common modules between them we end up with just the runtime code included in the manifest file
}),
new HtmlWebpackPlugin({
title: "einstein-js",
template: "./src/index.ejs",
favicon: "./src/einstein.ico"
}),
new PreloadWebpackPlugin({
rel: "prefetch",
include: "allAssets",
fileWhitelist: [/\.png$/],
as: "image"
}),
new webpack.NamedChunksPlugin(),
new CopyWebpackPlugin([
{
from: "./src/einstein-*.png", // TODO: don't hardcode icon png
to: "./",
flatten: true
}
])
]
};