forked from viabledata/developer-interview-task
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.common.js
More file actions
139 lines (129 loc) · 3.62 KB
/
webpack.common.js
File metadata and controls
139 lines (129 loc) · 3.62 KB
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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const sourcePath = path.join(__dirname, './app');
const buildDirectory = path.join(__dirname, './dist');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const { HashedModuleIdsPlugin } = require('webpack');
const hashing = process.env.NODE_ENV === 'production' ? 'chunkhash' : 'hash';
console.log(`content hashing: ${hashing}`);
module.exports = {
resolve: {
extensions: ['.js', '.jsx', '.json'],
modules: [path.resolve(__dirname), 'node_modules', sourcePath],
},
output: {
path: buildDirectory,
filename: `[name].[${hashing}].js`,
chunkFilename: `[name].[${hashing}].chunk.js`,
publicPath: '/',
crossOriginLoading: 'anonymous',
},
plugins: [
new HashedModuleIdsPlugin({
hashFunction: 'sha256',
hashDigest: 'hex',
hashDigestLength: 20,
}),
new MiniCssExtractPlugin({
filename: `[name].[${hashing}].css`,
chunkFilename: `[name].[${hashing}].chunk.css`,
}),
new MomentLocalesPlugin({
localesToKeep: ['es-gb'],
}),
new HtmlWebpackPlugin({
title: 'Caching',
template: './public/index.html',
favicon: './public/favicon.ico',
}),
new CopyWebpackPlugin([
{ from: 'node_modules/govuk-frontend/govuk/assets', to: 'assets' },
]),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
Tooltip: 'exports-loader?Tooltip!bootstrap/js/dist/tooltip',
Tether: 'tether',
'window.Tether': 'tether',
React: 'react',
ReactDOM: 'react-dom',
}),
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
use: [{
loader: 'babel-loader',
}],
exclude: /node_modules/,
include: path.join(__dirname, 'app'),
}, {
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { url: false, sourceMap: true } },
{ loader: 'postcss-loader', options: {} },
],
}, {
test: /\.bpmn$/,
use: [{
loader: 'file-loader',
options: {
name: 'diagrams/[name].[ext]',
},
}],
}, {
test: /\.(png|jpg|gif)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'url-loader',
options: {
name: 'img/[name].[ext]',
},
}],
}, {
test: /\.(eot|com|ttf|woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'url-loader',
options: {
mimetype: 'application/octet-stream',
name: 'fonts/[name].[ext]',
},
}],
}, {
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
use: [{
loader: 'url-loader',
options: {
mimetype: 'image/svg+xml',
name: 'img/[name].[ext]',
},
}],
}, {
test: /\.less$/,
use: [{
loader: 'style-loader', // creates style nodes from JS strings
}, {
loader: 'css-loader', // translates CSS into CommonJS
}, {
loader: 'less-loader', // compiles Less to CSS
}],
}, {
test: /\.scss$/,
use: [{
loader: 'style-loader',
}, {
loader: 'css-loader',
}, {
loader: 'sass-loader',
options: {
includePaths: ['node_modules/**/*.scss'],
},
}],
}],
},
};