-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwebpack.config.babel.js
157 lines (140 loc) · 3.77 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
import path from 'path';
import cssnano from 'cssnano';
import webpack from 'webpack';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
const __DEV__ = process.env.NODE_ENV === 'development';
let devtool = 'cheap-module-eval-source-map';
const root = (_path = '.') => path.join(__dirname, _path);
const entry = {
app: [root('./src/index.js')]
};
const resolve = {
extensions: ['', '.js', '.jsx'],
root: root('./src'),
alias: {
'react': 'preact-compat/dist/preact-compat.js',
'react-dom': 'preact-compat/dist/preact-compat.js'
}
};
const output = {
path: root('./dist'),
filename: '[name].[hash].js',
publicPath: '/'
};
const baseCssLoader =
'css-loader?sourceMap&-minimize&' +
'modules&importLoaders=1&localIdentName=[name]_[local]_[hash:base64:5]';
const loaders = [
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/
},
{ test: /\.woff(\?.*)?$/, loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff' },
{ test: /\.woff2(\?.*)?$/, loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/font-woff2' },
{ test: /\.otf(\?.*)?$/, loader: 'file-loader?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=font/opentype' },
{ test: /\.ttf(\?.*)?$/, loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=application/octet-stream' },
{ test: /\.eot(\?.*)?$/, loader: 'file-loader?prefix=fonts/&name=[path][name].[ext]' },
{ test: /\.svg(\?.*)?$/, loader: 'url-loader?prefix=fonts/&name=[path][name].[ext]&limit=10000&mimetype=image/svg+xml' },
{ test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' }
];
const postcss = [
cssnano({
autoprefixer: {
add: true,
remove: true,
browsers: ['last 2 versions']
},
discardComments: {
removeAll: true
},
discardUnused: false,
mergeIdents: false,
reduceIdents: false,
safe: true,
sourcemap: true
})
];
const plugins = [
new webpack.DefinePlugin({
__DEV__
}),
new HtmlWebpackPlugin({
template: root('./src/index.ejs'),
filename: root('./dist/index.html'),
title: 'Preact Starter',
inject: 'body'
})
];
if (__DEV__) {
entry.app.unshift(root('./build/dev-client.js'));
loaders.push(
{
test: /\.css$/,
loader: 'style-loader!' + baseCssLoader + '!postcss-loader',
exclude: null
},
{
test: /\.less$/,
loader: 'style-loader!' + baseCssLoader + '!less-loader!postcss-loader',
exclude: null
}
);
plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
);
} else {
devtool = 'source-map';
entry.vendor = [
'preact',
'preact-compat/dist/preact-compat.js',
'react-router',
'mobx',
'mobx-react'
];
loaders.push(
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', baseCssLoader + '!postcss-loader'),
exclude: null
},
{
test: /\.less$/,
loader: ExtractTextPlugin.extract('style-loader', baseCssLoader + '!less-loader!postcss-loader'),
exclude: null
}
);
plugins.push(
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.optimize.UglifyJsPlugin({
compress: {
unused: true,
dead_code: true,
warnings: false
}
}),
new webpack.optimize.CommonsChunkPlugin({
names: ['vendor']
}),
new ExtractTextPlugin('[name].[contenthash].css', {
allChunks: true
}),
new CopyWebpackPlugin([
{from: root('./static'), to: 'static'}
])
);
}
export default {
devtool,
entry,
resolve,
output,
module: {
loaders
},
plugins,
postcss
};