forked from opengovsg/FormSG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
113 lines (111 loc) · 2.8 KB
/
webpack.common.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
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const GoogleFontsPlugin = require('google-fonts-plugin')
const CopyPlugin = require('copy-webpack-plugin')
module.exports = [
// Javascript / HTML config
{
entry: [path.resolve(__dirname, 'src/public/main.js')],
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
options: {
configFile: 'ts-loader-config.json',
},
},
{
test: /\.html$/,
loader: 'html-loader',
options: {
minimize: true,
},
},
{
test: /\.worker\.js$/,
// Don't transpile polyfills
exclude: /@babel(?:\/|\\{1,2})runtime|core-js/,
use: [
{
loader: 'worker-loader',
options: { publicPath: '/public/' },
},
{
loader: 'babel-loader',
},
],
},
],
},
resolve: {
alias: {
shared: path.resolve(__dirname, 'src/shared/'),
},
extensions: ['.ts', '.js'],
},
plugins: [
new CopyPlugin({
patterns: [
{ from: 'src/public/modules/core/img', to: 'modules/core/img' },
{
from: 'src/public/modules/forms/admin/img',
to: 'modules/forms/admin/img',
},
{ from: 'src/public/robots.txt', to: 'robots.txt' },
{ from: 'src/public/translations', to: 'translations' },
],
}),
],
output: {
path: path.resolve(__dirname, 'dist/frontend/'),
filename: 'bundle.js',
},
},
// CSS config
{
context: path.resolve(__dirname, 'src/public'),
entry: './main.css',
module: {
rules: [
{
test: /\.(jpe?g|png|gif|svg)$/,
loader: 'url-loader',
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(woff|woff2|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
},
},
],
},
output: {
path: path.resolve(__dirname, 'dist/frontend/'),
filename: 'bundle.css.js', // Throwaway file used by the CSS plugin
},
plugins: [
new MiniCssExtractPlugin({ filename: 'bundle.css' }),
new GoogleFontsPlugin({
fonts: [
{
family: 'Muli',
variants: ['200', '300', '400', '600', '700'],
subsets: ['latin'],
},
{
family: 'Source Sans Pro',
variants: ['300', '400', '600', '700', '900'],
subsets: ['latin'],
},
],
formats: ['woff', 'woff2'],
}),
],
},
]