forked from youlikeapp/youlikeapp.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
121 lines (100 loc) · 3.24 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
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 CommonsChunkPlugin = require("webpack/lib/optimize/CommonsChunkPlugin");
const { CheckerPlugin } = require('awesome-typescript-loader');
var getPath = function (pathToFile) { return path.resolve(__dirname, pathToFile); }
var ENV = process.env.npm_lifecycle_event;
var isProd = ENV === 'build';
module.exports = (function makeWebpackConfig() {
var config = {};
config.entry = {
'app': './src/app/index.ts',
'vendor': './src/app/vendor.ts'
};
config.output = {
path: isProd ? getPath("./") : getPath('./dist'),
filename: isProd ? '[name].[hash].js' : '[name].bundle.js',
chunkFilename: isProd ? '[name].[hash].js' : '[name].bundle.js',
publicPath: isProd ? '/' : 'http://localhost:8080/'
};
config.devtool = 'source-map';
config.resolve = {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js']
};
config.module = {
loaders: [
{
// TS LOADER
test: /\.ts$/,
loader: 'ng-annotate!awesome-typescript-loader',
include: [
getPath("src/app")
]
},
{
// JS LOADER
test: /\.js$/,
loader: 'babel',
include: [
getPath("src/app")
]
},
{
// SCSS LOADER - generates a separate CSS file, and adds the link to <head>
test: /\.scss$/,
loader: isProd ? ExtractTextPlugin.extract('style', 'css!postcss!sass') : 'style!css!sass'
},
/**
* To keep CSS bundled in with the generated JS, uncomment this section
*/
// {
// test: /\.scss$/,
// loader: 'style!css!sass'
// },
{
// ASSET LOADER
test: /\.(png|jpe?g|gif|svg|woff|woff2|ttf|eot|ico)$/,
loader: 'file?name=assets/[name].[hash].[ext]'
},
{
// HTML LOADER
test: /\.html$/,
loader: 'raw',
exclude: /(index)/
}
]
};
config.postcss = [
autoprefixer({
browsers: ['last 2 versions']
})
];
config.plugins = [
new CommonsChunkPlugin({
names: ['vendor'],
minChunks: Infinity
}),
new HtmlWebpackPlugin({
template: getPath('./src/index.html'),
inject: 'body'
}),
new CheckerPlugin()
];
if (isProd) {
config.plugins.push(
// Create separate CSS file
new ExtractTextPlugin('app.css'),
// Dedupe modules in the output
new webpack.optimize.DedupePlugin(),
// Minifiy all JS, switch loaders to minimizing mode
new webpack.optimize.UglifyJsPlugin()
);
}
config.devServer = {
contentBase: './src'
}
return config;
})();