Skip to content
This repository was archived by the owner on Feb 17, 2024. It is now read-only.

Commit 732deef

Browse files
committed
chore: convert webpack.config to ts
1 parent 5650ef8 commit 732deef

File tree

2 files changed

+179
-159
lines changed

2 files changed

+179
-159
lines changed

webpack.config.js

-159
This file was deleted.

webpack.config.ts

+179
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
import 'core-js/es6';
2+
import 'core-js/es7/reflect';
3+
import 'ts-helpers';
4+
// needed to create context for resolveNgRoute
5+
/**
6+
* @author: @AngularClass
7+
*/
8+
const {
9+
ContextReplacementPlugin,
10+
HotModuleReplacementPlugin,
11+
DefinePlugin,
12+
ProgressPlugin,
13+
14+
optimize: {
15+
CommonsChunkPlugin,
16+
DedupePlugin
17+
}
18+
19+
} = require('webpack');
20+
const {ForkCheckerPlugin} = require('awesome-typescript-loader');
21+
const resolveNgRoute = require('@angularclass/resolve-angular-routes')
22+
23+
const path = require('path');
24+
25+
function root(__path = '.') {
26+
return path.join(__dirname, __path);
27+
}
28+
29+
// type definition for WebpackConfig at the bottom
30+
function webpackConfig(options: EnvOptions = {}): WebpackConfig {
31+
32+
const CONSTANTS = {
33+
ENV: JSON.stringify(options.ENV),
34+
HMR: options.HMR,
35+
PORT: 3000,
36+
HOST: 'localhost'
37+
};
38+
39+
return {
40+
cache: true,
41+
// devtool: 'hidden-source-map',
42+
devtool: 'source-map',
43+
// devtool: 'cheap-module-eval-source-map',
44+
45+
46+
entry: {
47+
polyfills: './src/polyfills.browser',
48+
vendor: './src/vendor.browser',
49+
main: './src/main.browser'
50+
},
51+
52+
output: {
53+
path: root('dist'),
54+
filename: '[name].bundle.js',
55+
sourceMapFilename: '[name].map',
56+
chunkFilename: '[id].chunk.js'
57+
},
58+
59+
module: {
60+
preLoaders: [
61+
// fix angular2
62+
{
63+
test: /systemjs_component_resolver\.js$/,
64+
loader: 'string-replace-loader',
65+
query: {
66+
search: 'lang_1\\.global.*[\\n\\r]\\s*\\.System.import',
67+
replace: 'System.import',
68+
flags: 'g'
69+
}
70+
}
71+
],
72+
// End AngularSystemJS
73+
74+
loaders: [
75+
// Support for .ts files.
76+
{
77+
test: /\.ts$/,
78+
loaders: [
79+
'awesome-typescript-loader',
80+
'@angularclass/conventions-loader'
81+
],
82+
exclude: [/\.(spec|e2e|d)\.ts$/]
83+
},
84+
{ test: /\.json$/, loader: 'json-loader' },
85+
{ test: /\.html/, loader: 'raw-loader' },
86+
{ test: /\.css$/, loader: 'raw-loader' },
87+
]
88+
89+
},
90+
91+
92+
plugins: [
93+
new ContextReplacementPlugin(
94+
/angular\/core\/src\/linker/,
95+
root('./src'),
96+
resolveNgRoute(root('./src'))
97+
),
98+
new HotModuleReplacementPlugin(),
99+
new ForkCheckerPlugin(),
100+
new CommonsChunkPlugin({ name: ['main', 'vendor', 'polyfills'], minChunks: Infinity }),
101+
new DefinePlugin(CONSTANTS),
102+
new ProgressPlugin({})
103+
],
104+
105+
resolve: {
106+
extensions: ['', '.ts', '.js', '.json'],
107+
},
108+
109+
devServer: {
110+
contentBase: './src',
111+
port: CONSTANTS.PORT,
112+
hot: CONSTANTS.HMR,
113+
inline: CONSTANTS.HMR,
114+
historyApiFallback: true
115+
},
116+
117+
node: {
118+
global: 'window',
119+
process: true,
120+
Buffer: false,
121+
crypto: 'empty',
122+
module: false,
123+
clearImmediate: false,
124+
setImmediate: false,
125+
clearTimeout: true,
126+
setTimeout: true
127+
}
128+
};
129+
}
130+
131+
132+
// Export
133+
module.exports = webpackConfig;
134+
135+
136+
// Types
137+
type Entry = Array<string> | Object;
138+
139+
type Output = Array<string> | {
140+
path: string,
141+
filename: string
142+
};
143+
144+
type EnvOptions = any;
145+
146+
interface WebpackConfig {
147+
cache?: boolean;
148+
target?: string;
149+
devtool?: string;
150+
entry: Entry;
151+
output: any;
152+
module?: any;
153+
// module?: {
154+
// loaders?: Array<any>
155+
// };
156+
plugins?: Array<any>;
157+
resolve?: {
158+
root?: string;
159+
extensions?: Array<string>;
160+
};
161+
devServer?: {
162+
contentBase?: string;
163+
port?: number;
164+
historyApiFallback?: boolean;
165+
hot?: boolean;
166+
inline?: boolean;
167+
};
168+
node?: {
169+
process?: boolean;
170+
global?: boolean | string;
171+
Buffer?: boolean;
172+
crypto?: string | boolean;
173+
module?: boolean;
174+
clearImmediate?: boolean;
175+
setImmediate?: boolean
176+
clearTimeout?: boolean;
177+
setTimeout?: boolean
178+
};
179+
}

0 commit comments

Comments
 (0)