forked from italia/developers.italia.it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
115 lines (104 loc) · 2.96 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
114
115
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: './assets/index.js',
// Path and filename of your result bundle.
// Webpack will bundle all JavaScript into this file
output: {
path: path.resolve(__dirname, '_site/dist'),
filename: 'bundle.js'
},
resolve: {
alias: {
'jquery': require.resolve('jquery'),
},
},
plugins: [
// Provide global symbols for legacy plugins.
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
PhotoSwipe: 'photoswipe',
PhotoSwipeUI_Default: 'photoswipe/src/js/ui/photoswipe-ui-default.js',
PerfectScrollbar: 'perfect-scrollbar',
}),
// Pass down environment variables to process.env.
//
// If a variable is set, its value takes precedence over
// the default value defined here.
new webpack.EnvironmentPlugin({
ELASTICSEARCH_FRONTEND_URL: 'https://elasticsearch.developers.italia.it',
}),
// Just copy images and icons we reference directly in the HTML, we
// don't need to bundle those.
new CopyWebpackPlugin({
patterns: [
{ from: 'assets/images', to: '../assets/images' },
{ from: 'assets/icons', to: '../assets/icons' },
{ from: 'node_modules/bootstrap-italia/dist/svg/sprite.svg', to: '../assets/svg/' },
]}),
// Generate an output CSS file instead of using style injection with Javascript,
// to minimize the chance of FOUC.
new MiniCssExtractPlugin(),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
plugins: ['@babel/plugin-transform-react-jsx'],
},
},
},
{ test: /\.handlebars$/, loader: "handlebars-loader" },
{
// Handle .sass, .scss and .css files
test: /\.(sa|sc|c)ss$/,
// The first loader will be applied after others
use: [
MiniCssExtractPlugin.loader,
{
// Resolves url() and @imports inside CSS
loader: "css-loader",
options: { importLoaders: 2 },
},
// Autoprefixer and minifying
"postcss-loader",
// SASS to CSS
"sass-loader",
]
},
{
// Load images
test: /\.(png|jpe?g|gif|svg)$/,
use: [
{
loader: "file-loader",
options: {
outputPath: 'images'
}
}
]
},
{
// Load fonts
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'fonts/'
}
}
]
},
],
},
};