-
Notifications
You must be signed in to change notification settings - Fork 12
/
webpack.config.js
133 lines (127 loc) · 2.94 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
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const pkg = require('./package.json');
const cwd = process.cwd();
const production = process.env.NODE_ENV === 'production';
const library = process.env.LIBRARY_NAME || 'yarn';
const assets = 'assets';
const entry = {
css: {
filename: {
in: `${ library }`,
out: `${ library }`
},
extension: {
in: 'less',
out: 'css'
}
},
icon: {
filename: {
in: `${ library }-icon`,
out: `${ library }-icon`
},
extension: {
in: 'less',
out: 'css'
}
},
logo: {
filename: {
in: `${ library }-logo`,
out: `${ library }-logo`
},
extension: {
in: 'less',
out: 'css'
}
}
};
/**
* Returns the current date in English string format.
* @returns {string} Release date.
*/
function getReleaseDate() {
return (new Date()).toLocaleDateString('en-en', {
weekday: 'long',
year: 'numeric',
month: 'short',
day: 'numeric'
});
}
/**
* Returns the current year.
* @returns {string} Current year.
*/
function getYear() {
return (new Date()).toLocaleDateString('en-en', { year: 'numeric' });
}
module.exports = {
entry: Object.keys(entry).reduce((result, key) => {
const filename = entry[key].filename.in;
const extension = entry[key].extension.in;
result[filename] = `./src/${ extension }/${ filename }.${ extension }`;
return result;
}, {}),
output: {
filename: '[name]',
path: path.resolve(cwd, './dist'),
library,
libraryTarget: 'umd'
},
externals: {},
module: {
rules: [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/
}, {
test: /\.(css|less)$/,
use: ExtractTextPlugin.extract({
use: [
{
loader: 'css-loader',
options: {
sourceMap: true
}
}, {
loader: 'postcss-loader',
options: {
sourceMap: true
}
}, {
loader: 'less-loader',
options: {
sourceMap: true
}
}
]
})
}, {
test: /\.(eot|svg|ttf|woff(2)?)$/,
loader: `file-loader?name=${ assets }/[name].[ext]`
}
]
},
plugins: [
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true
}),
new webpack.BannerPlugin({
banner: `
${ pkg.name } v${ pkg.version }
Copyright adidas ${ getYear() }
Release date: ${ getReleaseDate() }
`.trim()
}),
...Object.keys(entry).map((key) => new webpack.optimize.CommonsChunkPlugin({
name: entry[key].filename.in,
filename: `${ entry[key].filename.out }.${ entry[key].extension.out }`,
chunks: [ entry[key].filename.in ]
}))
],
devtool: production ? 'source-map' : 'inline-source-map'
};