forked from ng-harmony-zz/ng-harmony-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
144 lines (136 loc) · 4.3 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
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
var path = require("path");
var webpack = require("webpack");
var autoprefixer = require("autoprefixer");
var HtmlWebpackPlugin = require("html-webpack-plugin");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var CopyWebpackPlugin = require("copy-webpack-plugin");
var ENV = process.env.npm_lifecycle_event;
var isTest = ENV === "test" || ENV === "test-watch";
var isProd = ENV === "build";
let config = {
entry: isTest ? void 0 : ["babel-polyfill", "./client/src/app.js"],
output: {
filename: isProd
? "[name].[hash].js"
: "[name].bundle.js",
path: path.resolve(__dirname, "dist"),
chunkFilename: isProd
? "[name].[hash].js"
: "[name].bundle.js"
},
devtool: isProd
? "source-map"
: (isTest
? "inline-source-map"
: "eval-source-map"),
devServer: {
contentBase: "./client",
stats: "minimal"
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules\/(?!ng-harmony.*\/).*/,
use: {
loader: "babel-loader",
options: {
presets: [
"env", "es2017", "stage-0"
],
plugins: [
"transform-async-functions",
"transform-decorators-legacy",
"transform-class-properties"
]
}
}
}, {
test: /\.html$/,
use: [
{
loader: "html-loader",
options: {
minimize: true
}
}
]
}, {
test: /\.(sass|scss)$/,
use: [
{
loader: "style-loader" // creates style nodes from JS strings
}, {
loader: "css-loader" // translates CSS into CommonJS
}, {
loader: "sass-loader", // compiles Sass to CSS
options: {
includePaths: ["/node_modules/inuitcss"]
}
}
]
}, {
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
"file-loader?hash=sha512&digest=hex&name=[hash].[ext]", {
"loader": "image-webpack-loader",
"query": {
"mozjpeg": {
"progressive": true
},
"gifsicle": {
"interlaced": false
},
"optipng": {
"optimizationLevel": 4
},
"pngquant": {
"quality": "75-90",
"speed": 3
}
}
}
]
}, {
test: /\.(eot|svg|ttf|woff|woff2)$/,
loader: "file-loader?name=fonts/[name].[ext]"
}
]
},
resolve: {
mainFields: ["browser", "module", "main"]
},
externals: {
fs: "{}"
},
cache: false
};
if (isTest) {
config.module.rules.push({
enforce: "pre",
test: /\.js$/,
exclude: [
/node_modules/, /\.spec\.js$/
],
loader: "istanbul-instrumenter-loader",
query: {
esModules: true
}
});
}
config.plugins = [];
if (!isTest) {
config.plugins.push(new HtmlWebpackPlugin({ template: "./client/index.html", inject: "body" }), new ExtractTextPlugin({
"filename": "css/[name].css",
disable: !isProd,
allChunks: true
}));
}
if (isProd) {
config.plugins.push(new webpack.NoErrorsPlugin(), new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin(), new CopyWebpackPlugin([
{
from: __dirname + "/client"
}
]))
}
module.exports = config;