-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack_optimised.config.js
96 lines (81 loc) · 3.13 KB
/
webpack_optimised.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
/**
* Webpack configuration - generates HTML with full optimisations (using bundling, cache-busting, minification) ready for
* deployment. Call with --env.production to enable automatic minification using HtmlWebpackPlugin
**/
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const StyleExtHtmlWebpackPlugin = require("style-ext-html-webpack-plugin");
const CopyPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
module.exports = {
entry: './src/spotlight.js',
output: {
path : path.resolve(__dirname, 'dist'),
filename : 'spotlight.[contenthash].js',
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
dropdsown: "exports-loader?dropdown!bootstrap/js/dist/dropdown",
}),
new CleanWebpackPlugin({
dry : false,
verbose : true,
}),
new HtmlWebpackPlugin({
title : 'Spotlight',
filename : 'index.html',
template : './src/spotlight.html',
scriptLoading : 'defer',
inject : false,
/* Prevent automatic insertion of CSS link tag, as it will inlined, but specify postiion of bundled.js in the lodash template. */
/* _Lodash template params. */
static: false
}),
new MiniCssExtractPlugin({
filename : 'spotlight.css',
chunkFilename : '[id].css',
}),
new StyleExtHtmlWebpackPlugin({
position: 'head-bottom',
minify: true /*clean-css*/
}),
new CopyPlugin({
patterns: [
{ from: './license.txt', to: '../dist/license.txt' },
{ from: './notice.txt', to: '../dist/notice.txt' },
{ from: './readme_html.md', to: '../dist/readme.md' },
],
}),
],
module: {
rules: [
/* Images - uses require(lodash template), HtmlWebpackPlugin and file-loader to pickup and process(copy to dist). */
{
test: /\.(png|svg|jpg|gif)$/,
loader: 'file-loader',
options: {
name: "images/[name].[ext]",
esModule: false
/* Fixes [object,object] appearing on spotlight.html template when require(file) processed by lodash in HtmlWebpackPlugin.*/
}
},
/* SASS-CSS-Extract-Internalise\Inline - uses StyleExtHtmlWebpackPlugin*/
{
test: /\.s[ac]ss$/i,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
},
},
'css-loader',
'sass-loader',
],
},
],
},
};