This repository has been archived by the owner on Oct 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
webpack.config.js
104 lines (87 loc) · 2.29 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* eslint-env node */
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const CssoWebpackPlugin = require('csso-webpack-plugin').default;
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
// Store environment variable to allow switches between
// dev server and production builds.
const ENV = process.env.NODE_ENV || 'development';
var config = {
entry: {
'js/dist/imageset.js': './assets/js/src/imageset.js',
'js/dist/respimage.js': './assets/js/src/respimage.js',
'css/imageset.css': './assets/scss/imageset.scss',
},
output: {
filename: '[name]',
path: path.resolve(__dirname, 'assets'),
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
},
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
allChunks: true,
//fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: (ENV === 'development'),
}
},
'resolve-url-loader',
{
loader: 'postcss-loader',
options: {
sourceMap: (ENV === 'development'),
},
},
{
loader: 'sass-loader',
options: {
sourceMap: (ENV === 'development'),
precision: 10,
data: `$ENV: ${ENV};`,
}
},
],
}),
},
],
},
stats: {
colors: true
},
plugins: [
new ExtractTextPlugin({
filename: (getPath) => {
'use strict';
return getPath('[name]');
},
allChunks: true
}),
],
};
if(ENV === 'development') {
config.devtool = 'source-map';
}
if(ENV === 'production') {
config.entry['js/dist/imageset.min.js'] = './assets/js/src/imageset.js';
config.entry['js/dist/respimage.min.js'] = './assets/js/src/respimage.js';
config.plugins.push(new UglifyJsPlugin({
include: /\.min\.js$/,
}));
config.plugins.push(new CssoWebpackPlugin({
pluginOutputPostfix: 'min',
}));
}
module.exports = config;