-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
111 lines (107 loc) · 2.65 KB
/
webpack.config.babel.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
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import autoprefixer from 'autoprefixer';
import precss from 'precss';
import webpack from 'webpack';
import { execFileSync } from 'child_process';
import packageInfo from './package.json';
const extractCss = new ExtractTextPlugin('main.css');
const headerParam = {
project: packageInfo.name,
description: packageInfo.description,
source: packageInfo.homepage,
license: packageInfo.license,
commit: execFileSync(
'git',
[
'log',
'-1',
'--date=iso',
'--pretty=format:%cd\n %H\n %cn: %s'
]
),
contact: '[email protected] – twitter.com/studiomoniker – github.com/studiomoniker',
love: 'Moniker'
};
function generateHeader() {
const toUppercase = (str) => str.charAt(0).toUpperCase() + str.slice(1);
let header = '';
for (var name in headerParam) {
if (headerParam[name]) {
header += ` ${toUppercase(name)} – ${headerParam[name]}\n\n`;
}
}
return ` <!--\n\n${header} -->`;
}
module.exports = {
context: __dirname,
entry : ['./src/app.js', './style/main.scss'],
output : {
path : __dirname + '/dist',
filename : 'main.js'
},
module : {
loaders: [
{
test : /.js$/,
loader : 'babel-loader',
query: {
presets: ['es2015']
}
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
test: /\.scss$/,
loader: extractCss.extract('style', 'css!postcss-loader!sass')
},
{
test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
loader: 'url'
}
]
},
postcss: function () {
return [
autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}),
precss
];
},
plugins: [
new webpack.DefinePlugin({
'process.env': Object
.keys(process.env)
.reduce(function(o, k) {
o[k] = JSON.stringify(process.env[k]);
return o;
}, {})
}),
extractCss,
new CopyWebpackPlugin(
[
{ from: 'assets' }
],
{
ignore: [
'*.woff',
'*.woff2',
'*.ttf',
'*.otf',
{ dot: false }
]
}
),
new HtmlWebpackPlugin({
template: './index.html',
inject: false,
header: generateHeader(),
title: packageInfo.description + ' by Moniker'
})
]
};