-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
154 lines (141 loc) · 3.88 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
const path = require('path');
// `CheckerPlugin` is optional. Use it if you want async error reporting.
// We need this plugin to detect a `--watch` mode. It may be removed later
// after https://github.com/webpack/webpack/issues/3460 will be resolved.
const webpack = require('webpack');
const { CheckerPlugin } = require('awesome-typescript-loader');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const assets = [
];
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
const outputPath = isDevBuild
? path.join(__dirname, './dist/public')
: path.join(__dirname, './docs');
return {
entry: {
app: './src/public/js/app.ts',
// work: './src/public/js/work.ts',
},
output: {
path: outputPath,
filename: 'js/[name].js',
publicPath: '/',
},
// Currently we need to add '.ts' to the resolve.extensions array.
resolve: {
extensions: ['.ts', '.tsx', '.js', '.jsx'],
alias: {
jquery: 'jquery/src/jquery',
},
},
externals: [
(context, request, callback) => {
if (/^(jquery|\$)$/i.test(request)) {
return callback(null, 'jQuery');
}
if (/^(d3|d3-.*)$/i.test(request)) {
return callback(null, 'd3');
}
if ('slick-carousel' === request) {
return callback(null, 'jQuery');
}
return callback();
},
],
// Source maps support ('inline-source-map' also works)
devtool: 'source-map',
// Add the loader for .ts files.
module: {
loaders: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
}, {
test: /\.json$/,
loader: 'json-loader',
}, {
test: /\.scss$/,
use: ExtractTextPlugin.extract({
use: [{
loader: 'css-loader',
options: {
importLoaders: 1,
minimize: true,
sourceMap: true,
},
}, {
loader: 'postcss-loader',
options: {
sourceMap: true,
},
}, {
loader: 'sass-loader',
options: {
sourceMap: true,
},
}],
}),
}, {
test: /\.(png|jpg)$/,
use: [{
loader: 'url-loader',
options: {
limit: 8192,
mimetype: 'image/png',
fallback: {
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]',
outputPath: 'media/images/',
},
},
},
}],
}, {
test: /\.svg$/,
loader: 'svg-inline-loader',
}, {
test: /\.(woff|woff2)$/,
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]',
outputPath: 'media/fonts/',
},
}],
},
],
},
plugins: [
new CheckerPlugin(),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
jquery: 'jquery',
}),
new CopyWebpackPlugin(
assets.map(a => {
return {
from: path.resolve(__dirname, `./node_modules/${a}`),
to: path.resolve(__dirname, './dist/lib'),
};
})
),
new CopyWebpackPlugin([
{ from: path.resolve(__dirname, './src/public') },
]),
new ExtractTextPlugin({
filename: 'css/[name].css',
}),
new webpack.optimize.UglifyJsPlugin({
compress: { warnings: false },
sourceMap: true,
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': isDevBuild ? '"development"' : '"production"',
}),
],
};
};