Skip to content

Commit d588416

Browse files
committed
simplify webpack.config
1 parent 24b77ae commit d588416

File tree

2 files changed

+33
-73
lines changed

2 files changed

+33
-73
lines changed

karma.conf.js

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,6 @@ module.exports = function (config) {
2626
{
2727
test: /\.ts$/,
2828
loader: 'ts',
29-
query: {
30-
ignoreDiagnostics: [
31-
2300,
32-
2383,
33-
2375,
34-
2374
35-
]
36-
},
3729
exclude: [
3830
/\.min\.js$/,
3931
/node_modules/

webpack.config.js

Lines changed: 33 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,40 @@ var CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
1313
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
1414
var DedupePlugin = webpack.optimize.DedupePlugin;
1515
var DefinePlugin = webpack.DefinePlugin;
16-
var BannerPlugin = webpack.BannerPlugin;
1716

17+
var plugins = [
18+
new DefinePlugin({
19+
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
20+
'VERSION': JSON.stringify(pkg.version)
21+
}),
22+
new OccurenceOrderPlugin(),
23+
new DedupePlugin(),
24+
new CommonsChunkPlugin({
25+
name: 'angular2',
26+
minChunks: Infinity,
27+
filename: 'angular2.js'
28+
}),
29+
new CommonsChunkPlugin({
30+
name: 'common',
31+
filename: 'common.js'
32+
})
33+
];
1834

19-
/*
20-
* Config
21-
*/
22-
var config = {
35+
if (NODE_ENV === 'production') {
36+
plugins.push(new UglifyJsPlugin({
37+
compress: {
38+
warnings: false,
39+
drop_debugger: false
40+
},
41+
output: {
42+
comments: false
43+
},
44+
beautify: false
45+
})
46+
)
47+
}
48+
49+
module.exports = {
2350
devtool: 'source-map',
2451
debug: true,
2552
cache: true,
@@ -95,15 +122,6 @@ var config = {
95122
{
96123
test: /\.ts$/,
97124
loader: 'ts',
98-
query: {
99-
'ignoreDiagnostics': [
100-
2300, // 2300 -> Duplicate identifier
101-
2309, // 2309 -> An export assignment cannot be used in a module with other exported elements.
102-
2383,
103-
2375,
104-
2374
105-
]
106-
},
107125
exclude: [
108126
/\.min\.js$/,
109127
/\.spec\.ts$/,
@@ -128,61 +146,11 @@ var config = {
128146
/rtts_assert\/src\/rtts_assert/,
129147
/reflect-metadata/
130148
]
131-
}
132-
};
133-
134-
var commons_chunks_plugins = [
135-
{
136-
name: 'angular2',
137-
minChunks: Infinity,
138-
filename: 'angular2.js'
139149
},
140-
{
141-
name: 'common',
142-
filename: 'common.js'
143-
}
144-
];
145150

146-
var environment_plugins = {
147-
all: [
148-
new DefinePlugin({
149-
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
150-
'VERSION': pkg.version
151-
}),
152-
new OccurenceOrderPlugin(),
153-
new DedupePlugin()
154-
],
155-
production: [
156-
new UglifyJsPlugin({
157-
compress: {
158-
warnings: false,
159-
drop_debugger: false
160-
},
161-
output: {
162-
comments: false
163-
},
164-
beautify: false
165-
}),
166-
new BannerPlugin(getBanner(), {entryOnly: true})
167-
],
168-
development: []
151+
plugins: plugins
169152
};
170153

171-
// create CommonsChunkPlugin instance for each config
172-
var combine_common_chunks = commons_chunks_plugins.map(function (config) {
173-
return new CommonsChunkPlugin(config);
174-
});
175-
176-
// combine everything
177-
config.plugins = [].concat(combine_common_chunks, environment_plugins.all, environment_plugins[NODE_ENV]);
178-
179-
module.exports = config;
180-
181-
// Helper functions
182-
function getBanner() {
183-
return 'Spring Boot and Angular2 tutorial v' + pkg.version + ' by Akira Sosa';
184-
}
185-
186154
function root(args) {
187155
args = sliceArgs(arguments, 0);
188156
return path.join.apply(path, [__dirname].concat(args));

0 commit comments

Comments
 (0)