-
Notifications
You must be signed in to change notification settings - Fork 48
/
webpack.config.babel.js
83 lines (80 loc) · 2.09 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
const webpack = require('webpack');
const path = require('path');
const IS_DIST = (process.argv.indexOf('--dist') !== -1) ? true : false;
const IS_DEPLOY = (process.argv.indexOf('--deploy') !== -1) ? true : false;
const STYLE_LOAD = 'css-loader!postcss-loader!sass-loader';
const STYLE_LOADER = (IS_DIST || IS_DEPLOY) ? ExtractTextPlugin.extract('style-loader', STYLE_LOAD) : `style-loader!${STYLE_LOAD}`;
const config = {
devServer: {
port: 1987
},
entry: {
demo: './src/script/demo'
},
output: {
path: `${__dirname}/public`,
filename: '[name][hash].js'
},
module: {
loaders: [
{
test: /\.js$/,
loader: 'babel',
include: /(src\/script)/,
query: {
presets: [
'es2015'
]
}
},
{
test: /\.scss$/,
include: /(src\/)/,
loader: STYLE_LOADER
},
{
test: /\.pug$/,
include: /(src\/markup)/,
loader: 'pug'
}
]
},
resolve: {
root: [
path.resolve('./src/script'),
path.resolve('./src/styles')
],
alias: {
ep: path.resolve(__dirname, 'src/script'),
'ep-styles': path.resolve(__dirname, 'src/styles')
},
extensions: [ '', '.js', '.styl' ]
},
plugins: [
new HtmlWebpackPlugin({
template: './src/markup/index.pug',
filename: 'index.html',
chunks: [ 'demo' ],
minify: {
collapseWhitespace: true
}
}),
(IS_DEPLOY) ? function () {} : new HtmlWebpackPlugin({
template: './src/markup/sandbox.pug',
filename: 'sandbox.html',
chunks: [ 'demo' ],
minify: {
collapseWhitespace: true
}
}),
(IS_DEPLOY) ? new ExtractTextPlugin('[name][hash].css') : function () {},
(IS_DEPLOY) ? new webpack.optimize.UglifyJsPlugin() : function () {}
],
postcss: function () {
return [ autoprefixer ];
}
}
module.exports = config;