-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.babel.js
119 lines (113 loc) · 2.71 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
'use strict';
import webpack from 'webpack';
import browserslist from 'browserslist';
import autoprefixer from 'autoprefixer';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import cfg from './build.config';
const IS_DEVELOPMENT = process.env.NODE_ENV !== 'production';
const config = {
context: `${__dirname}/src`,
entry: {
index: ['./index']
},
output: {
path: `${__dirname}/dist`,
publicPath: '/',
filename: '[name].js'
},
resolve: {
extensions: ['', '.js', '.scss']
},
devtool: IS_DEVELOPMENT ? null : 'source-map',
plugins: [
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
IS_DEVELOPMENT: JSON.stringify(IS_DEVELOPMENT)
}),
new ExtractTextPlugin('[name].css', {
allChunks: true,
disable: IS_DEVELOPMENT
}),
new HtmlWebpackPlugin ({
inject: true,
template: 'index.html',
minify: IS_DEVELOPMENT ? false : {
includeAutoGeneratedTags: true,
collapseWhitespace: true
}
})
],
module: {
loaders: [{
test: /\.scss$/,
include: `${__dirname}/src`,
loader: IS_DEVELOPMENT ?
'style!css!resolve-url!sass' :
ExtractTextPlugin.extract('css?minimize!postcss!resolve-url!sass')
}, {
test: /\.(png|jpg|svg|ttf|eot|woff|woff2)$/,
include: [
`${__dirname}/src/textures`
],
loader: 'file-loader?name=[path][name].[ext]'
}, {
test: /\.(png|jpg|svg|ttf|eot|woff|woff2)$/,
exclude: [
`${__dirname}/src/textures`
],
loader: 'url-loader?limit=10000&name=[path][name].[ext]'
}, {
test: /\.json/,
include: [
`${__dirname}/src/models`
],
loader: 'file-loader?name=[path][name].[ext]'
}, {
test: /\.json/,
include: [
`${__dirname}/src/fonts`
],
loader: 'file-loader?name=[path][name].[ext]'
}, {
test: /\.view.html/,
loader: 'html-loader'
}]
},
postcss: [autoprefixer({
browsers: browserslist(null, {
path: cfg.ext.browserslist
})
})],
sassLoader: {
data: `$is_development: ${IS_DEVELOPMENT};`
},
devServer: {
watchOptions: {
aggregateTimeout: 100
},
contentPath: 'dist/',
historyApiFalback: true
}
};
if(!IS_DEVELOPMENT) {
config.module.loaders.push({
test: /\.js$/,
include: `${__dirname}/src`,
loader: 'babel',
query: {
babelrc: false,
presets: ['es2015-webpack']
}
});
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
'drop_console': true,
unsafe: true
}
})
);
}
export default config;