Skip to content

Commit 7bd88df

Browse files
authored
Merge pull request #22 from pmargreff/master
Refactor webpack file
2 parents 72ee7bf + 2acac88 commit 7bd88df

1 file changed

Lines changed: 25 additions & 138 deletions

File tree

config/webpack.config.js

Lines changed: 25 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -7,148 +7,35 @@
77
* https://webpack.js.org/configuration/
88
*/
99

10-
var path = require('path');
1110
var webpack = require('webpack');
1211
var ionicWebpackFactory = require(process.env.IONIC_WEBPACK_FACTORY);
1312

1413
var ModuleConcatPlugin = require('webpack/lib/optimize/ModuleConcatenationPlugin');
1514
var PurifyPlugin = require('@angular-devkit/build-optimizer').PurifyPlugin;
1615

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-
new webpack.NormalModuleReplacementPlugin(/typeorm$/, function (result) {
97-
result.request = result.request.replace(/typeorm/, "typeorm/browser");
98-
}),
99-
new webpack.ProvidePlugin({
100-
'window.SQL': 'sql.js/js/sql.js'
101-
})
102-
],
103-
104-
// Some libraries import Node modules but don't use them in the browser.
105-
// Tell Webpack to provide empty mocks for them so importing them works.
106-
node: {
107-
fs: 'empty',
108-
net: 'empty',
109-
tls: 'empty'
110-
}
111-
};
112-
113-
var prodConfig = {
114-
entry: process.env.IONIC_APP_ENTRY_POINT,
115-
output: {
116-
path: '{{BUILD}}',
117-
publicPath: 'build/',
118-
filename: '[name].js',
119-
devtoolModuleFilenameTemplate: ionicWebpackFactory.getSourceMapperFunction(),
120-
},
121-
devtool: process.env.IONIC_SOURCE_MAP_TYPE,
122-
123-
resolve: {
124-
extensions: ['.ts', '.js', '.json'],
125-
modules: [path.resolve('node_modules')]
126-
},
127-
128-
module: {
129-
loaders: getProdLoaders()
130-
},
131-
132-
plugins: [
133-
ionicWebpackFactory.getIonicEnvironmentPlugin(),
134-
ionicWebpackFactory.getCommonChunksPlugin(),
135-
new ModuleConcatPlugin(),
136-
new PurifyPlugin(),
137-
new webpack.NormalModuleReplacementPlugin(/typeorm$/, function (result) {
138-
result.request = result.request.replace(/typeorm/, "typeorm/browser");
139-
})
140-
],
141-
142-
// Some libraries import Node modules but don't use them in the browser.
143-
// Tell Webpack to provide empty mocks for them so importing them works.
144-
node: {
145-
fs: 'empty',
146-
net: 'empty',
147-
tls: 'empty'
148-
}
16+
var useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js');
17+
18+
useDefaultConfig.dev.plugins = [
19+
ionicWebpackFactory.getIonicEnvironmentPlugin(),
20+
ionicWebpackFactory.getCommonChunksPlugin(),
21+
new webpack.NormalModuleReplacementPlugin(/typeorm$/, function (result) {
22+
result.request = result.request.replace(/typeorm/, "typeorm/browser");
23+
}),
24+
new webpack.ProvidePlugin({
25+
'window.SQL': 'sql.js/js/sql.js'
26+
})
27+
]
28+
29+
useDefaultConfig.prod.plugins = [
30+
ionicWebpackFactory.getIonicEnvironmentPlugin(),
31+
ionicWebpackFactory.getCommonChunksPlugin(),
32+
new ModuleConcatPlugin(),
33+
new PurifyPlugin(),
34+
new webpack.NormalModuleReplacementPlugin(/typeorm$/, function (result) {
35+
result.request = result.request.replace(/typeorm/, "typeorm/browser");
36+
})
37+
]
38+
39+
module.exports = function () {
40+
return useDefaultConfig;
14941
};
150-
151-
module.exports = {
152-
dev: devConfig,
153-
prod: prodConfig
154-
}

0 commit comments

Comments
 (0)