-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
91 lines (87 loc) · 2.71 KB
/
webpack.config.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
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const CleanWebpackPlugin = require("clean-webpack-plugin");
const webpack = require("webpack");
const path = require("path");
module.exports = function (env) {
// Define entries
let entries = {
initial: "./initial.js",
"vendor-react": ["react", "react-dom"],
};
// Define Plugins
const plugins = [
new webpack.optimize.CommonsChunkPlugin({
filename: "vendor-react.js",
name: "vendor-react",
chunks: ["vendor-react"]
}),
new webpack.optimize.CommonsChunkPlugin({
filename: "common.js",
name: "common",
}),
new ExtractTextPlugin({
allChunks: true,
disable: false,
filename: "[name].css",
})
];
// Define Dev tools
let devtool = "source-map";
return {
devServer: {
compress: true,
contentBase: path.join(__dirname, "dist"),
hot: true,
inline: true,
port: 8000,
},
devtool: devtool,
entry: entries,
module: {
rules: [
{
exclude: /node_modules/,
loader: "awesome-typescript-loader",
test: /\.tsx?$/,
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ["css-loader"],
}),
},
{
test: /\.less$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: ["css-loader", "less-loader"],
}),
},
{
include: /initial/,
test: /\.(jpe?g|gif|png|svg)$/,
use: "url-loader?limit=128000",
},
{
exclude: /initial/,
test: /\.(jpe?g|gif|png|svg)$/,
use: "file-loader?hash=sha512&digest=hex&name=images/[name].[ext]?[hash]",
},
{
test: /\.(ttf)$/,
use: "file-loader?name=fonts/[name].[ext]",
},
],
},
output: {
filename: "[name].js",
path: path.resolve(__dirname, "./dist"),
},
plugins: plugins,
resolve: {
extensions: [".tsx", ".ts", ".js", ".css", ".less"],
},
};
};