This repository has been archived by the owner on Jul 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
147 lines (135 loc) · 3.25 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
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
import * as path from 'path';
import * as webpack from 'webpack';
import * as CleanWebpackPlugin from 'clean-webpack-plugin';
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
import * as ExtractTextPlugin from 'extract-text-webpack-plugin';
import * as HtmlWebpackHarddiskPlugin from 'html-webpack-harddisk-plugin';
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
import * as DotenvPlugin from 'webpack-dotenv-plugin';
declare var __dirname;
// Dev server settings
const ip = process.env.APP_IP || '0.0.0.0';
const port = (+process.env.APP_PORT) || 3001;
// 3rd party stylesheets, not to be processed as CSS modules
const globalStyles: string[] = [
path.join(__dirname, 'node_modules/material-design-lite')
];
const cssModules: string[] = [
path.join(__dirname, 'src/views')
];
const config: webpack.Configuration = {
// Enable sourcemaps for debugging webpack's output.
devtool: 'source-map',
entry: {
app: [path.join(__dirname, 'src/bootstrap.ts')],
vendor: [
'jquery',
'lodash',
'backbone',
'handlebars',
'material-design-lite'
]
},
module: {
rules: [
{
test: /\.ts$/,
// https://github.com/s-panferov/awesome-typescript-loader/issues/375
loader: 'awesome-typescript-loader?silent=true'
},
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader'
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'typings-for-css-modules-loader?modules&importLoaders=1&namedExport&camelCase!postcss-loader'
}),
exclude: globalStyles,
include: cssModules,
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader'],
}),
exclude: cssModules,
include: globalStyles
},
{
test: /\.png$/,
loader: 'url-loader?prefix=images/&limit=8000&mimetype=image/png'
},
{
test: /\.jpg$/,
loader: 'url-loader?prefix=images/&limit=8000&mimetype=image/jpeg'
},
{
test: /\.svg$/,
loader: 'url-loader'
},
{
test: /\.woff$/,
loader: 'url-loader?prefix=fonts/&limit=8000&mimetype=application/font-woff'
},
{
test: /\.hbs$/,
loader: 'handlebars-loader'
},
{
test: /\.ttf$/,
loader: 'file-loader?prefix=fonts/'
},
{
test: /\.eot$/,
loader: 'file-loader?prefix=fonts/'
},
{
test: /\.json$/,
loader: 'json-loader'
}
]
},
output: {
filename: '[name].[hash].js',
path: path.join(__dirname, 'dist')
},
resolve: {
alias: {
app: path.resolve(__dirname, 'src'),
handlebars: 'handlebars/dist/handlebars.min.js'
},
extensions: ['.ts', '.js', '.json', '.hbs'],
modules: ['src', 'node_modules']
},
plugins: [
new webpack.WatchIgnorePlugin([
/css\.d\.ts$/
]),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, 'src', 'index.hbs'),
inject: false,
alwaysWriteToDisk: true,
path: 'dist/'
}),
new HtmlWebpackHarddiskPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: '[name].[hash].js',
minChunks: Infinity
}),
new ExtractTextPlugin({
filename: 'styles.[hash].css',
ignoreOrder: true
}),
new CleanWebpackPlugin(['dist'], {
allowExternal: true
}),
]
};
export default config;