-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
98 lines (91 loc) · 2.32 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
const path = require('path');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const webpack = require('webpack');
const autoprefixer = require('autoprefixer');
const dateFormat = require('dateformat');
const packageJson = require('./package.json');
const GitRevisionPlugin = require('git-revision-webpack-plugin')
const LOAD_FONT_FROM_CDN = [{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/fonts/"
}
}];
const EMBED_FONT = [{loader: "url-loader?prefix=font/&limit=5000000"}];
const isProd = process.env.npm_lifecycle_event === 'build';
const gitRevisionPlugin = new GitRevisionPlugin();
function commitHash() {
try {
return gitRevisionPlugin.commithash();
}
catch(doNothing) {
return null;
}
}
function linkToCommit() {
var commit = commitHash();
return packageJson.repository.url + (commit ? 'commit/'+commit : '');
}
module.exports = {
entry: "./src/js/index.js",
output: {
path: path.join(__dirname, "dist"),
libraryTarget: "var",
library: "Application",
filename: "all.js"
},
resolve: {
extensions: ['.js', '.elm'],
modules: ['node_modules']
},
module: {
noParse: /\.elm$/,
rules: [ {
test: /\.css$/,
use: ['style-loader', 'css-loader']
}, {
test: /\.scss$/,
use: [ 'style-loader', 'css-loader', 'sass-loader' ]
}, {
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
use: LOAD_FONT_FROM_CDN
}, {
test: /\.(woff)$/,
use: LOAD_FONT_FROM_CDN
}, {
test: /\.(woff2)$/,
use: EMBED_FONT
}, {
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
use: LOAD_FONT_FROM_CDN
}, {
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: LOAD_FONT_FROM_CDN
}, {
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
use: 'elm-webpack-loader'
}]
},
plugins: [
new UglifyJsPlugin(),
new webpack.LoaderOptionsPlugin({ options: { postcss: [autoprefixer()] } }),
new webpack.DefinePlugin({
BUILD_TIMESTAMP: JSON.stringify(dateFormat(new Date(), 'dd.mm.yyyy HH:MM:ss')),
PRODUCTION: JSON.stringify(isProd),
VERSION: JSON.stringify(packageJson.version),
COMMIT: JSON.stringify(commitHash()),
LINK_TO_COMMIT: JSON.stringify(linkToCommit())
})
],
performance: { hints: false },
mode: 'production'
}
if (!isProd) {
module.exports.devServer = {
historyApiFallback: true,
contentBase: './src',
hot: true
};
}