-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.babel.js
165 lines (154 loc) · 3.83 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import _ from 'lodash';
import path from 'path';
import webpack from 'webpack';
import fs from 'fs-extra';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import postcssAutoprefixerPlugin from 'autoprefixer';
import stylusRupturePlugin from 'rupture';
import HappyPack from 'happypack';
import responsiveCutoff from './ui/responsive.inc.js';
const extractProjectCSS = new ExtractTextPlugin('main.css', {allChunks: true});
const extractVendorCSS = new ExtractTextPlugin('vendors.css',
{allChunks: true});
function root(fn) {
return path.resolve(__dirname, fn);
}
function vjResponsivePlugin() {
return style => {
style.define('vjResponsiveCutoff', responsiveCutoff, true);
};
}
module.exports = {
context: root('ui'),
watchOptions: {
aggregateTimeout: 500,
},
entry: {
main: './Entry.js',
},
output: {
path: root('.uibuild'),
filename: '[name].js',
chunkFilename: '[name].chunk.js',
},
resolve: {
modules: [
root('node_modules'),
root('ui'),
],
extensions: ['.js'],
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules\//,
use: {
loader: 'eslint-loader',
options: {
configFile: root('.eslintrc.yml'),
},
},
},
{
// fonts
test: /\.(svg|ttf|eot|woff|woff2)/,
use: {
loader: 'file-loader',
options: {
name: '[path][name].[ext]?[sha512:hash:base62:7]',
},
},
},
{
// images
test: /\.(png|jpg)/,
use: {
loader: 'url-loader',
options: {
limit: 4024,
name: '[path][name].[ext]?[sha512:hash:base62:7]',
},
},
},
{
// babel
test: /\.js$/,
exclude: /node_modules\//,
use: 'happypack/loader',
},
{
// project stylus stylesheets
test: /\.styl$/,
use: extractProjectCSS.extract(
[
'css-loader',
'postcss-loader',
{
loader: 'stylus-loader',
options: {
'resolve url': true,
use: [
vjResponsivePlugin(),
stylusRupturePlugin(),
],
import: [
'~common/common.inc.styl',
],
},
},
]),
},
{
// vendors stylesheets
test: /\.css$/,
include: /node_modules\//,
use: extractVendorCSS.extract(['css-loader']),
},
{
// project stylesheets
test: /\.css$/,
exclude: /node_modules\//,
use: extractProjectCSS.extract(['css-loader', 'postcss-loader']),
},
],
},
plugins: [
new HappyPack({
loaders: [
{
loader: 'babel-loader',
options: {
'presets': ['env', 'stage-0'],
'plugins': ['lodash', 'transform-runtime'],
},
},
],
threads: 4,
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
}),
// don't include locale files in momentjs
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// extract stylesheets into a standalone file
extractVendorCSS,
extractProjectCSS,
// extract 3rd-party JavaScript libraries into a standalone file
new webpack.optimize.CommonsChunkPlugin({
name: 'vendors',
filename: 'vendors.js',
minChunks: (module, count) => (
module.resource
&& module.resource.indexOf(root('ui/')) === -1
&& module.resource.match(/\.js$/)
),
}),
// copy static assets
new CopyWebpackPlugin([{from: root('ui/static')}]),
],
};