-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
106 lines (90 loc) · 3.46 KB
/
webpack.config.ts
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/// <reference types="node" />
import * as path from 'path';
import * as webpack from 'webpack';
const AddAssetHtmlPlugin = require('add-asset-html-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
export const commonConfig = {
resolve: {
extensions: ['', '.ts', '.js'],
alias: {
'proxy-polyfill': path.resolve(__dirname, 'node_modules/proxy-polyfill/proxy.min.js')
}
},
module: {
preLoaders: [
{ test: /\.ts$/, loader: 'tslint' }
],
loaders: [
{ test: /\.js$/, loader: 'strip-sourcemap-loader' },
{ test: /\.css$/, loader: 'style!css' },
{ test: /\.scss$/, loader: 'style!css!sass' },
{ test: /\.ts$/, loader: 'ng-annotate!ts-loader!strip-sourcemap-loader' },
{ test: /\.woff(\?.+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
{ test: /\.woff2(\?.+)?$/, loader: 'url-loader?limit=10000&mimetype=application/font-woff' },
{ test: /\.ttf(\?.+)?$/, loader: 'file-loader' },
{ test: /\.eot(\?.+)?$/, loader: 'file-loader' },
{ test: /\.svg(\?.+)?$/, loader: 'file-loader' },
{ test: /\.html/, loader: 'raw' },
{ test: /\.po$/, loader: 'json!po?format=mf' },
{ test: /\.png$/, loader: 'url-loader?mimetype=image/png' },
{ test: /\.gif$/, loader: 'url-loader?mimetype=image/gif' }
]
}
};
const fastRebuild = true;
export function createConfig(build: boolean): Configuration {
const outputPath = path.join(__dirname, 'public');
const assetsPath = build ? path.join(outputPath, 'assets') : outputPath;
const buildEnv = {
NODE_ENV: JSON.stringify(process.env.NODE_ENV || 'development'),
GIT_DATE: JSON.stringify(process.env.GIT_DATE),
GIT_HASH: JSON.stringify(process.env.GIT_HASH),
FINTO_URL: JSON.stringify(process.env.FINTO_URL),
API_ENDPOINT: JSON.stringify(process.env.API_ENDPOINT)
};
const serveEnv = {
NODE_ENV: JSON.stringify('local')
};
const buildPlugins = [ new webpack.optimize.DedupePlugin(), new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) ];
const servePlugins = [ new webpack.HotModuleReplacementPlugin() ];
const plugins = [
new webpack.DefinePlugin({ 'process.env': build ? buildEnv : serveEnv }),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require(path.join(outputPath, 'vendor-manifest.json'))
}),
new HtmlWebpackPlugin({ template: 'src/index.html', filename: build ? '../index.html' : 'index.html' }),
new AddAssetHtmlPlugin({
filepath: require.resolve(path.join(outputPath, require(path.join(outputPath, 'assets.json')).vendor.js)),
includeSourcemap: true
}),
new webpack.NoErrorsPlugin(),
...(build ? buildPlugins : servePlugins)
];
return Object.assign({}, commonConfig, {
entry: {
init: './src/init.ts'
},
output: {
path: assetsPath,
filename: build ? '[name].[chunkhash].js' : '[name].js',
publicPath: build ? '/assets/' : '/'
},
debug: !build,
devtool: build ? 'source-map' : fastRebuild ? 'cheap-module-source-map' : 'source-map',
plugins
});
}
interface Configuration extends webpack.Configuration {
tslint?: {
configuration: {}
};
}
declare module 'webpack' {
interface DllReferencePluginStatic {
new (options: any): Plugin;
}
interface Webpack {
DllReferencePlugin: DllReferencePluginStatic;
}
}