-
Notifications
You must be signed in to change notification settings - Fork 3
/
webpack.config.js
238 lines (205 loc) · 5.91 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
var webpack = require('webpack');
var _ = require('lodash');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var WriteFilePlugin = require('write-file-webpack-plugin');
var path = require('path');
const ASSETS_LIMIT = typeof process.env.ASSETS_LIMIT !== 'undefined' ? parseInt(process.env.ASSETS_LIMIT, 10) : 5000; // limit bellow the assets will be inlines
var nodeEnvironment = process.env.BUILD;
var dist = path.join(__dirname, 'workbenches/simple-annoton-editor/public');
var app = path.join(__dirname, 'app');
var bs = path.join(__dirname, 'node_modules/bootstrap');
var bss = path.join(__dirname, 'node_modules/bootstrap-sass');
var uigrid = path.join(__dirname, 'node_modules`/a`ngular-ui-grid');
var fa = path.resolve(__dirname, 'node_modules/font-awesome');
var production = process.env.BUILD === 'production';
var lproduction = process.env.BUILD === 'lproduction';
var debugMode = !production;
console.log('production', production);
console.log('debugMode', debugMode);
var entryFile = './entry.js';
var outputPath = dist;
var outputFile = './bundle.js';
var indexFile = 'index.ejs';
var baseURL = (production || lproduction) ? '/simple-annoton-editor/' : '/';
var config = {
context: app,
entry: entryFile,
output: {
path: outputPath,
filename: outputFile,
publicPath: '/workbench/simple-annoton-editor/'
},
resolve: {
modules: [
app,
'node_modules'
]
},
plugins: [
new webpack.IgnorePlugin(/ringo\/httpclient/),
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin({
'INCLUDE_ALL_MODULES': function includeAllModulesGlobalFn(modulesArray, application) {
modulesArray.forEach(function executeModuleIncludesFn(moduleFn) {
moduleFn(application);
});
},
ENVIRONMENT: JSON.stringify(nodeEnvironment)
})
],
module: {
rules: [{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.scss$/,
// loader: 'style!css!sass?includePaths[]=' + bootstrap
loaders: [
'style-loader',
'css-loader?importLoaders=1',
'postcss-loader',
'sass-loader'
]
},
{
test: /\.json$/,
loader: 'json-loader'
},
{
// Reference: https://github.com/babel/babel-loader
test: /\.js$/,
loader: 'babel-loader',
query: {
// https://github.com/babel/babel-loader#options
cacheDirectory: true,
presets: ['env']
},
exclude: /node_modules/,
include: [app]
},
// {
// test: /\.(png|jpg|jpeg|gif|ico)$/,
// loader: 'file-loader',
// include: [bs, bss, uigrid, app]
// },
// {
// test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
// loader: 'url-loader?limit=10000',
// include: [fa, bs, bss, uigrid]
// },
{
test: /\.(png)$/,
loader: 'url-loader?limit=' + ASSETS_LIMIT + '&name=assets/[hash].[ext]'
},
{
test: /\.woff(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=' + ASSETS_LIMIT + '&mimetype=application/font-woff&name=assets/[hash].[ext]'
},
{
test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=' + ASSETS_LIMIT + '&mimetype=application/font-woff&name=assets/[hash].[ext]'
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=' + ASSETS_LIMIT + '&mimetype=application/octet-stream&name=assets/[hash].[ext]'
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader?&name=assets/[hash].[ext]'
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=' + ASSETS_LIMIT + '&mimetype=image/svg+xml&&name=assets/[hash].[ext]'
},
{
test: /\.(html)$/,
loader: 'html-loader',
exclude: /node_modules/
},
{
test: /\.(tmpl)$/,
loader: 'html-loader',
exclude: /node_modules/
}
]
},
node: {
fs: 'empty'
},
devServer: {
hot: false,
inline: true,
contentBase: dist,
watchContentBase: true,
historyApiFallback: true,
headers: {
"Access-Control-Allow-Origin": "*"
}
},
};
config.plugins.push(
new CopyWebpackPlugin([{
from: 'inject.tmpl'
}, {
from: 'templates/**/*'
}, {
from: 'grid-templates/**/*'
}, {
from: 'dialogs/**/*'
}, {
from: 'assets/**/*'
}]));
config.plugins.push(
new WriteFilePlugin());
// config.plugins.push(
// new HtmlWebpackPlugin({
// template: path.join(app, indexFile),
// inject: 'head',
// baseURL: baseURL
// }));
switch (nodeEnvironment) {
/* eslint no-fallthrough: 0 */
case 'lproduction':
case 'production':
if (!debugMode) {
config.plugins.push(
new webpack.LoaderOptionsPlugin({
minimize: true,
debug: false
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
beautify: false,
mangle: {
screw_ie8: true,
keep_fnames: true
},
compress: {
warnings: true,
screw_ie8: true
},
comments: false
})
);
}
// config.plugins.push(new webpack.optimize.CommonsChunkPlugin({name: 'vendor', minChunks: Infinity}));
config.output.filename = '[name].js';
config.entry = {
bundle: entryFile,
// vendor: ['angular', 'angular-ui-router', 'lodash']
};
config.devtool = 'source-map';
break;
case 'test':
config.entry = entryFile;
break;
case 'development':
config.entry = [entryFile, 'webpack/hot/dev-server'];
config.devtool = 'source-map';
break;
default:
console.warn('Unknown or Undefined Node Environment. Please refer to package.json for available build commands.');
}
module.exports = config;