-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
86 lines (77 loc) · 1.87 KB
/
webpack.config.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
'use strict';
const DEV_ENV = 'dev';
const PROD_ENV = 'prod';
const ENV = process.env.NODE_ENV || DEV_ENV;
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin')
let extractCssTextPlugin = 'css!sass';
if (ENV == PROD_ENV) {
extractCssTextPlugin = 'css?minimize!sass';
}
module.exports = {
context: `${__dirname}/task3/src`,
entry: {
index: './index',
common: ['./js/constants/constants'],
styles: './styles/main.sass'
},
output: {
path: `${__dirname}/task3/dist/js`,
publicPath: '/task3/dist/js/',
filename: '[name].js',
library: '[name]'
},
watch: ENV == DEV_ENV,
watchOptions: {
aggregateTimeout: 100
},
module: {
loaders: [
{
test: /\.js?$/,
include: `${__dirname}/task3/src`,
loader: 'babel-loader',
query: {
presets: ['es2015'],
plugins: ['add-module-exports']
}
},
{
test: /\.pug?$/,
include: `${__dirname}/task3/src`,
loader: 'pug-loader'
},
{
test: /\.sass?$/,
include: `${__dirname}/task3/src`,
loader: ExtractTextPlugin.extract('style' , extractCssTextPlugin)
}
// it can be file/url loader, but no static files
]
},
plugins: [
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
ENV: JSON.stringify(ENV)
}),
new webpack.optimize.CommonsChunkPlugin(
{
name: 'common'
}
),
new ExtractTextPlugin('../assets/styles/[name].css', {allChunks: true})
],
devServer: {
host: 'localhost',
port: 8081,
contentBase: `${__dirname}/task3`
}
}
if (ENV == PROD_ENV) {
module.exports.plugins.push(
new webpack.optimize.UglifyJsPlugin({
warnings: false,
drop_console: true
})
);
}