-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
115 lines (99 loc) · 3.05 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
// Based on https://github.com/preboot/angular-webpack/blob/master/webpack.config.js
// Helper: root() is defined at the bottom
var path = require('path');
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var ENV = process.env.ENV;
var isDeploy = ENV === 'deploy';
var isProd = (ENV === 'prod') || isDeploy;
var isDev = (ENV === 'dev') || (!isProd);
var envText = isDeploy ? 'deploy' : isProd ? 'prod' : 'dev'
console.debug('Resolved build environment: ' + envText);
// Webpack Plugins
var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
var autoprefixer = require('autoprefixer');
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = () => {
var config = {};
if (isDev) {
config.devtool = 'eval-source-map';
} else {
config.devtool = 'source-map';
}
config.entry = {
app: './prez-tweet-ui/main.ts',
polyfill: './prez-tweet-ui/polyfill.ts',
vendor: './prez-tweet-ui/vendor.ts',
};
config.output = {
path: root('dist', envText),
filename: '[name].bundle.js',
};
config.resolve = {
extensions: ['.ts', '.js', '.json', '.css', '.scss', '.html'],
alias: [{
alias: 'jquery',
name: 'jquery/src/jquery',
}],
};
var atlConfigFile = root('prez-tweet-ui', 'tsconfig.json');
config.module = {
rules: [
{test: require.resolve("jquery"), loaders: ["expose-loader?$", "expose-loader?jQuery"] },
{test: /\.ts$/, loader: 'awesome-typescript-loader?configFileName=' + atlConfigFile},
{test: /\.(gif|png|jpg|svg|woff|woff2|ttf|eot)$/, loader: 'file-loader'},
{test: /\.json$/, loader: 'json-loader'},
{test: /\.(css|scss|sass)$/, loaders: ['to-string-loader', 'css-loader', 'sass-loader']},
{test: /\.html$/, loader: 'html-loader'}
]
};
config.plugins = [
new CopyWebpackPlugin([{
from: root('prez-tweet-ui', 'static'),
flatten: true,
}]),
new CommonsChunkPlugin({
name: ['vendor', 'polyfill'],
}),
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
jquery: 'jquery',
}),
new webpack.LoaderOptionsPlugin({
options: {
postcss: [
require('autoprefixer')(),
]
}
}),
new webpack.DefinePlugin({
'process.env': {
ENV: JSON.stringify(envText),
}
}),
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
template: root('prez-tweet-ui', 'index.html'),
chunksSortMode: 'dependency',
}),
];
if (isProd) {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({sourceMap: true, mangle: { keep_fnames: true }})
);
}
config.devServer = {
contentBase: root('prez-tweet-ui'),
historyApiFallback: true,
quiet: false,
stats: 'normal', // none (or false), errors-only, minimal, normal (or true) and verbose
port: process.env.WEBPACK_DEV_SERVER_PORT || 8888,
};
return config
}
// Helper functions
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [__dirname].concat(args));
}