-
Notifications
You must be signed in to change notification settings - Fork 23
/
webpack.parts.js
162 lines (148 loc) · 4.26 KB
/
webpack.parts.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
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const AssetsPlugin = require('assets-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
exports.staticLoader = function (target) {
var filename = '[name].[ext]';
if (target === 'BUILD') {
filename = '[name].[hash].[ext]';
}
return {
module: {
loaders: [
{
test: /\.(jpg|png|gif)$/,
loader: 'url?limit=25000&digest=hex&size=16&name=images/' + filename,
},
{
test: /\.svg/,
loader: 'svg-url-loader?limit=25000&digest=hex&size=16&name=images/' + filename
},
{
test: /\.(woff|woff2|ttf|eot)$/i,
loader: 'file',
query: {
name: 'fonts/' + filename
},
}
// Load css via js
// {
// test: /\.(css|scss|sass)$/,
// loader: 'css'
// // loaders: ["style", "css", "sass"],
// // include: 'app/static/src/styles'
// }
]
}
}
}
exports.assetsJson = function () {
return {
plugins: [
new AssetsPlugin({
filename: 'app/build/assets.json',
prettyPrint: true,
})
]
}
}
exports.babelLoader = function() {
return {
module: {
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['es2015','react'],
}
}
]
}
};
}
exports.minify = function() {
return {
plugins: [
new webpack.optimize.DedupePlugin(),
new webpack.DefinePlugin({
'process.env.NODE_ENV': '"production"'
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.optimize.OccurenceOrderPlugin(),
new webpack.optimize.AggressiveMergingPlugin(),
new webpack.NoErrorsPlugin()
]
};
}
exports.extractBundle = function(options) {
const entry = {};
entry[options.name] = options.entries;
return {
entry: entry, // Define an entry point needed for splitting.
plugins: [
new webpack.optimize.CommonsChunkPlugin({
names: [options.name, 'manifest'] // Extract bundle and manifest files. Manifest is needed for reliable caching.
})
]
};
}
exports.clean = function(path) {
return {
plugins: [
new CleanWebpackPlugin([path], {
root: process.cwd()
})
]
};
}
exports.extractCSS = function(path, target) {
var filename = 'style/[name].css';
if (target === 'BUILD') {
filename = 'style/[name].[chunkhash].css';
}
return {
module: {
loaders: [
{
test: /\.(css|scss|sass)$/i,
loader: ExtractTextPlugin.extract('style', 'css?sourceMap', 'sass?sourceMap'),
include: path
}
]
},
plugins: [
new ExtractTextPlugin(filename, {
allChunks: true
})
]
};
}
exports.copyFiles = function (destination) {
return {
plugins: [
new CopyWebpackPlugin([
{
context: 'app/templates',
from: '**/*.html',
to: destination
},
{
from: 'app/static/src/robots.txt',
to: destination,
},
{
from: 'app/static/src/favicon.png',
to: destination,
}
])
]
}
}