forked from ionic-team/ionic-app-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
86 lines (72 loc) · 2.02 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
var path = require('path');
var webpack = require('webpack');
var ionicWebpackFactoryPath = path.join(process.env.IONIC_APP_SCRIPTS_DIR, 'dist', 'webpack', 'ionic-webpack-factory.js');
var ionicWebpackFactory = require(ionicWebpackFactoryPath);
function getEntryPoint() {
if (process.env.IONIC_ENV === 'prod') {
return '{{TMP}}/app/main.prod.js';
}
return '{{SRC}}/app/main.dev.ts';
}
function getPlugins() {
if (process.env.IONIC_ENV === 'prod') {
return [
// This helps ensure the builds are consistent if source hasn't changed:
new webpack.optimize.OccurrenceOrderPlugin(),
// Try to dedupe duplicated modules, if any:
// Add this back in when Angular fixes the issue: https://github.com/angular/angular-cli/issues/1587
//new DedupePlugin()
];
}
// for dev builds, use our custom environment
return [
ionicWebpackFactory.getIonicEnvironmentPlugin()
];
}
function getSourcemapLoader() {
if (process.env.IONIC_ENV === 'prod') {
// TODO figure out the disk loader, it's not working yet
return [];
}
return [
{
test: /\.ts$/,
loader: path.join(process.env.IONIC_APP_SCRIPTS_DIR, 'dist', 'webpack', 'typescript-sourcemap-loader-memory.js')
}
];
}
function getDevtool() {
if (process.env.IONIC_ENV === 'prod') {
// for now, just force source-map for prod builds
return 'source-map';
}
return process.env.IONIC_SOURCE_MAP;
}
module.exports = {
entry: getEntryPoint(),
output: {
path: '{{BUILD}}',
filename: 'main.js'
},
devtool: getDevtool(),
resolve: {
extensions: ['.js', '.ts', '.json'],
modules: [path.resolve('{{ROOT}}', 'node_modules')]
},
module: {
loaders: [
{
test: /\.json$/,
loader: 'json'
}
].concat(getSourcemapLoader())
},
plugins: getPlugins(),
// Some libraries import Node modules but don't use them in the browser.
// Tell Webpack to provide empty mocks for them so importing them works.
node: {
fs: 'empty',
net: 'empty',
tls: 'empty'
}
};