-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
165 lines (135 loc) · 3.41 KB
/
webpack.config.js
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
'use strict';
const
path = require('path'),
webpack = require('webpack'),
StatsWriterPlugin = require('webpack-stats-plugin').StatsWriterPlugin,
HtmlWebpackPlugin = require('html-webpack-plugin'),
pkg = require('./package.json');
module.exports = () => {
// The main webpack config object to return
let wpConfig = {
mode: 'development'
};
/**
* Dev Server Configuration
*/
wpConfig.devServer = {
port: 4200,
stats: {
modules: false,
colors: true
},
watchOptions: {
aggregateTimeout: 500,
poll: 1000
}
};
/**
* Source map configuration
*/
// Source maps for development (provides trace back to original TS)
wpConfig.devtool = 'source-map';
/**
* Entry points for the program
*
* 'vendor' - All third-party dependencies of the application
* 'application' - Application code
*/
wpConfig.entry = {
application: path.posix.resolve('./src/demo/main.ts')
};
/**
* Bundle output definitions
* Defines how output bundles are generated and named
*/
wpConfig.output = {
path: path.posix.resolve('./public'),
publicPath: '/',
filename: '[name].js',
chunkFilename: '[name].js'
};
/**
* List of extensions that webpack should try to resolve
*/
wpConfig.resolve = {
extensions: [ '.ts', '.js','.json' ]
};
/**
* Module Loaders for webpack
* Teach webpack how to read various types of referenced dependencies
*/
wpConfig.module = {
// Configured loaders
rules: [
{
// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
// Removing this will cause deprecation warnings to appear.
test: /[\/\\]@angular[\/\\]core[\/\\].+\.js$/,
parser: { system: true }, // enable SystemJS
},
// Typescript loader
{
test: /\.ts$/,
use: 'awesome-typescript-loader'
},
// Template Loader
{
test: /\.ts$/,
use: 'angular2-template-loader',
enforce: 'pre',
exclude: [/\.(spec|e2e)\.ts$/]
},
// Add source maps for dependencies
{
test: /node_modules\/*\.js$/,
use: 'source-map-loader',
enforce: 'pre'
},
// CSS and SCSS loader
{
test: /\.(css|scss)$/,
use: [ 'to-string-loader', 'style-loader', 'css-loader', 'sass-loader' ]
},
// Image file loader
{ test: /\.png$/, use: 'file-loader' },
{ test: /\.(gif|jpg|jpeg)$/, use: 'file-loader' },
// Font file loader (mostly for bootstrap/font-awesome)
{ test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/, use: 'file-loader' },
// Font file loader (mostly for bootstrap/font-awesome)
{ test: /\.(ttf|eot|svg)(\?[\s\S]+)?$/, use: 'file-loader' },
// HTML file loader
{ test: /\.html$/, use: 'html-loader' }
]
};
wpConfig.optimization = {
splitChunks: {
chunks: 'all',
}
};
/**
* Webpack plugins
*/
wpConfig.plugins = [];
// Chunk common code if we're not running in test mode
wpConfig.plugins.push(
new webpack.ProvidePlugin({
// Declare global libraries here (eg. D3, JQuery, etc)
// d3: 'd3'
}),
// Stats writer generates a file with webpack stats that can be analyzed at https://chrisbateman.github.io/webpack-visualizer/
new StatsWriterPlugin({
chunkModules: true,
filename: 'webpack-stats.json',
fields: null
}),
new webpack.ContextReplacementPlugin(
/(.+)?angular(\\|\/)core(.+)?/,
path.posix.resolve('./src')
),
new HtmlWebpackPlugin({
template: path.posix.resolve('./src/demo/index.html'),
inject: 'body'
})
);
return wpConfig;
};