Skip to content

Commit 01e1551

Browse files
dotansimhadarkbasic
authored andcommitted
Step 1.4: Add Ionic's base webpack file to the project
1 parent a70f9a9 commit 01e1551

File tree

1 file changed

+147
-0
lines changed

1 file changed

+147
-0
lines changed

webpack.config.js

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* The webpack config exports an object that has a valid webpack configuration
3+
* For each environment name. By default, there are two Ionic environments:
4+
* "dev" and "prod". As such, the webpack.config.js exports a dictionary object
5+
* with "keys" for "dev" and "prod", where the value is a valid webpack configuration
6+
* For details on configuring webpack, see their documentation here
7+
* https://webpack.js.org/configuration/
8+
*/
9+
10+
var path = require('path');
11+
var webpack = require('webpack');
12+
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY);
13+
14+
var ModuleConcatPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin');
15+
var PurifyPlugin = require('@angular-devkit/build-optimizer').PurifyPlugin;
16+
17+
var optimizedProdLoaders = [
18+
{
19+
test: /\.json$/,
20+
loader: 'json-loader'
21+
},
22+
{
23+
test: /\.js$/,
24+
loader: [
25+
{
26+
loader: process.env.IONIC_CACHE_LOADER
27+
},
28+
29+
{
30+
loader: '@angular-devkit/build-optimizer/webpack-loader',
31+
options: {
32+
sourceMap: true
33+
}
34+
},
35+
]
36+
},
37+
{
38+
test: /\.ts$/,
39+
loader: [
40+
{
41+
loader: process.env.IONIC_CACHE_LOADER
42+
},
43+
44+
{
45+
loader: '@angular-devkit/build-optimizer/webpack-loader',
46+
options: {
47+
sourceMap: true
48+
}
49+
},
50+
51+
{
52+
loader: process.env.IONIC_WEBPACK_LOADER
53+
}
54+
]
55+
}
56+
];
57+
58+
function getProdLoaders() {
59+
if (process.env.IONIC_OPTIMIZE_JS === 'true') {
60+
return optimizedProdLoaders;
61+
}
62+
return devConfig.module.loaders;
63+
}
64+
65+
var devConfig = {
66+
entry: process.env.IONIC_APP_ENTRY_POINT,
67+
output: {
68+
path: '{{BUILD}}',
69+
publicPath: 'build/',
70+
filename: '[name].js',
71+
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
72+
},
73+
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
74+
75+
resolve: {
76+
extensions: ['.ts', '.js', '.json'],
77+
modules: [path.resolve('node_modules')]
78+
},
79+
80+
module: {
81+
loaders: [
82+
{
83+
test: /\.json$/,
84+
loader: 'json-loader'
85+
},
86+
{
87+
test: /\.ts$/,
88+
loader: process.env.IONIC_WEBPACK_LOADER
89+
}
90+
]
91+
},
92+
93+
plugins: [
94+
ionicWebpackFactory.getIonicEnvironmentPlugin(),
95+
ionicWebpackFactory.getCommonChunksPlugin()
96+
],
97+
98+
// Some libraries import Node modules but don't use them in the browser.
99+
// Tell Webpack to provide empty mocks for them so importing them works.
100+
node: {
101+
fs: 'empty',
102+
net: 'empty',
103+
tls: 'empty'
104+
}
105+
};
106+
107+
var prodConfig = {
108+
entry: process.env.IONIC_APP_ENTRY_POINT,
109+
output: {
110+
path: '{{BUILD}}',
111+
publicPath: 'build/',
112+
filename: '[name].js',
113+
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
114+
},
115+
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
116+
117+
resolve: {
118+
extensions: ['.ts', '.js', '.json'],
119+
modules: [path.resolve('node_modules')]
120+
},
121+
122+
module: {
123+
loaders: getProdLoaders()
124+
},
125+
126+
plugins: [
127+
ionicWebpackFactory.getIonicEnvironmentPlugin(),
128+
ionicWebpackFactory.getCommonChunksPlugin(),
129+
new ModuleConcatPlugin(),
130+
new PurifyPlugin()
131+
],
132+
133+
// Some libraries import Node modules but don't use them in the browser.
134+
// Tell Webpack to provide empty mocks for them so importing them works.
135+
node: {
136+
fs: 'empty',
137+
net: 'empty',
138+
tls: 'empty'
139+
}
140+
};
141+
142+
143+
module.exports = {
144+
dev: devConfig,
145+
prod: prodConfig
146+
}
147+

0 commit comments

Comments
 (0)