forked from sillsdev/web-languageforge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
156 lines (140 loc) · 4.64 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
'use strict';
var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');
var LiveReloadPlugin = require('webpack-livereload-plugin');
var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
// Webpack Config
var webpackConfig = {
entry: {},
output: {
publicPath: '',
path: path.resolve(__dirname, 'src', 'dist')
},
plugins: [
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), // to not to load all locales
new CopyWebpackPlugin([
{ from: './node_modules/font-awesome/', to: 'font-awesome' },
{ from: './node_modules/intl-tel-input/build/', to: 'intl-tel-input' },
{ from: './node_modules/jquery/dist/', to: 'jquery' },
{ from: './node_modules/offline-js/offline.min.js', to: 'offline-js' },
{ from: './node_modules/rangy/lib/', to: 'rangy' },
{ from: './node_modules/zxcvbn/dist/', to: 'zxcvbn' }
]),
new webpack.ContextReplacementPlugin(
// The ([\\/]) piece accounts for path separators in *nix and Windows
/angular([\\/])core([\\/])@angular/,
path.resolve(__dirname, './src'),
// your Angular Async Route paths relative to this root directory
{}
),
new webpack.DefinePlugin({
'process.env.XFORGE_BUGSNAG_API_KEY': JSON.stringify(process.env.XFORGE_BUGSNAG_API_KEY
|| 'missing-bugsnag-api-key'),
'process.env.NOTIFY_RELEASE_STAGES': process.env.NOTIFY_RELEASE_STAGES,
})
],
module: {
rules: [
{ test: /\.ts$/, use: 'awesome-typescript-loader' },
{ test: /\.s?css$/, use: ['style-loader', 'css-loader', 'sass-loader'] },
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: 'url-loader?limit=10000'
},
{ test: /\.(ttf|eot|svg)(\?[\s\S]+)?$/, use: 'file-loader' },
{ test: /\.(png|jpg)$/, use: 'url-loader?limit=8192' },
{
// fix critical dependency warning by removing reference to require() in Bridge
test: /bridge\.js/,
use: {
loader: 'string-replace-loader',
query: {
search: ' || require(name)',
replace: ''
}
}
},
{
// fix conflict between System namespace in Bridge and System variable injection
test: /(newtonsoft\.json|machine|bridge)\.js/,
parser: { system: false }
}
]
}
};
// Our Webpack Defaults
var defaultConfig = {
devtool: 'source-map',
output: {
filename: '[name].bundle.js',
sourceMapFilename: '[name].map',
chunkFilename: '[id].chunk.js'
},
resolve: {
extensions: ['.ts', '.js'],
modules: [path.resolve(__dirname, 'node_modules')]
},
devServer: {
historyApiFallback: true,
watchOptions: { aggregateTimeout: 300, poll: 1000 },
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization'
}
},
node: {
global: true,
crypto: 'empty',
__dirname: true,
__filename: true,
process: true,
Buffer: false,
clearImmediate: false,
setImmediate: false,
fs: 'empty'
}
};
module.exports = function (env) {
if (env == null) {
env = {
applicationName: 'languageforge',
isTest: false
};
}
var mainPath = './src/angular-app/' + env.applicationName + '/main' + (env.isTest ? '.specs' : '') + '.ts';
webpackConfig.entry.main = mainPath;
if (env.isTest) {
webpackConfig.devtool = false;
var plugins = [
new webpack.SourceMapDevToolPlugin({
filename: null, // if no value is provided the sourcemap is inlined
test: /\.(ts|js)($|\?)/i // process .js and .ts files only
})
];
webpackConfig.plugins = webpackConfig.plugins.concat(plugins);
} else {
var plugins = [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
// this assumes your vendor imports exist in the node_modules or js/assets directories
return module.context && (
module.context.indexOf('node_modules') !== -1 ||
module.context.indexOf('js/assets') !== -1 ||
module.context.indexOf('js/vendor') !== -1 ||
module.context.indexOf('core/input-systems') !== -1
);
}
}),
// CommonChunksPlugin will now extract all the common modules from vendor and main bundles
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest'
}),
new LiveReloadPlugin()
];
webpackConfig.plugins = webpackConfig.plugins.concat(plugins);
}
return webpackMerge(defaultConfig, webpackConfig);
};