-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.js
More file actions
171 lines (148 loc) · 5 KB
/
config.js
File metadata and controls
171 lines (148 loc) · 5 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/**
* @author Stanislav Kalashnik <darkpark.main@gmail.com>
* @license GNU GENERAL PUBLIC LICENSE Version 3
*/
'use strict';
var util = require('util'),
path = require('path'),
extend = require('extend'),
webpack = require('webpack'),
config = require('spa-plugin/config'),
pkgData = require(path.join(process.cwd(), 'package.json')),
wpkData = require(path.join(path.dirname(require.resolve('webpack')), '..', 'package.json')),
srcPath = path.join(config.source, 'js'),
dstPath = path.join(config.target, 'js'),
profiles = {};
// main
profiles.release = extend(true, {}, config, {
// source files location
source: srcPath,
// output files location
target: dstPath,
// dir for temp files
//cache: path.join(srcPath, '.cache'),
// build config
webpack: {
// the entry point for the bundle
entry: './' + path.join(srcPath, 'main.js'),
// options affecting the output of the compilation
output: {
filename: 'release.js',
path: dstPath,
sourceMapFilename: 'release.map'
},
// affecting the resolving of modules
resolve: {
alias: {
// config.js file in js root
'app:config': path.join(process.cwd(), srcPath, 'config.js')
}
},
// options affecting the normal modules
// NormalModuleFactory
module: {
// don't parse files matching
// they are expected to have no call to require, define or similar
noParse: [/\.min\.js$/, /livereload\.js$/],
loaders: [
{
test: /\.json$/,
loader: 'json'
}
//{
// test: /cjs-validator/,
// loader: 'less'
//}
]
},
// rebuilds on file change mode
watchOptions: {
// delay the rebuilt after the first change (in ms)
aggregateTimeout: 50
},
// choose a developer tool to enhance debugging
devtool: 'source-map',
// additional functionality
plugins: [
//new webpack.IgnorePlugin(/cjs-validator/),
// fix compilation persistence
//new webpack.optimize.OccurenceOrderPlugin(true),
// global constants
new webpack.DefinePlugin({
DEVELOP: false
}),
// obfuscation
new webpack.optimize.UglifyJsPlugin({
// this option prevents name changing
// use in case of strange errors
// mangle: false,
sourceMap: false,
output: {
comments: false,
keep_quoted_props: true
},
/* eslint camelcase: 0 */
compress: {
// display warnings when dropping unreachable code or unused declarations etc.
warnings: false,
unused: true,
dead_code: true,
drop_console: true,
drop_debugger: true,
properties: false,
pure_funcs: [
// todo: check and rework this list
'debug.assert', 'debug.log', 'debug.info', 'debug.warn', 'debug.fail', 'debug.inspect',
'debug.event', 'debug.stub', 'debug.time', 'debug.timeEnd'
]
}
}),
// add comment to the top of app.js
new webpack.BannerPlugin(util.format(
'%s v%s (webpack: v%s)',
pkgData.name, pkgData.version, wpkData.version
))
]
},
// false to prevent watch task creation
// otherwise array of globs to monitor
watch: [path.join(config.source, 'js', '**', '*.js')],
// info channels
notifications: {
popup: {
info: {icon: path.join(__dirname, 'media', 'info.png')},
warn: {icon: path.join(__dirname, 'media', 'warn.png')},
fail: {icon: path.join(__dirname, 'media', 'fail.png')}
}
}
});
// additional
profiles.develop = extend(true, {}, profiles.release, {
// build config
webpack: {
// options affecting the output of the compilation
output: {
pathinfo: true,
filename: 'develop.js',
sourceMapFilename: 'develop.map'
},
// choose a developer tool to enhance debugging
//devtool: 'eval',
// polyfills or mocks
node: {
Buffer: false,
__filename: true,
__dirname: true
}
}
});
// overwrite all plugins
profiles.develop.webpack.plugins = [
// global constants
new webpack.DefinePlugin({
DEVELOP: true,
LIVERELOAD: require('spa-plugin-livereload/config').default.tinylr
})
];
// public
module.exports = profiles;