-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.common.js
113 lines (108 loc) · 2.63 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 { resolve } = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackInjector = require('html-webpack-injector');
const ImageminWebpackPlugin = require('imagemin-webpack-plugin').default;
const ImageminMozjpeg = require('imagemin-mozjpeg');
const webcomponentsjs = './node_modules/@webcomponents/webcomponentsjs';
const polyfills = [
{
from: resolve(`${webcomponentsjs}/webcomponents-bundle.js`),
to: 'vendor',
flatten: true,
},
{
from: resolve(`${webcomponentsjs}/webcomponents-bundle.js.map`),
to: 'vendor',
flatten: true,
},
{
from: resolve(`${webcomponentsjs}/webcomponents-loader.js`),
to: 'vendor',
flatten: true,
},
{
from: resolve(`${webcomponentsjs}/bundles/`),
to: 'vendor/bundles',
flatten: true,
},
{
from: resolve(`${webcomponentsjs}/custom-elements-es5-adapter.js`),
to: 'vendor',
flatten: true,
},
];
module.exports = {
entry: {
polyfill_head: resolve(__dirname, 'src/utils/polyfill.js'),
main: resolve(__dirname, 'src/index.ts'),
},
output: {
filename: '[name].bundle.js',
path: resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.css|\.s([ca])ss$/,
exclude: resolve(__dirname, 'src/styles'),
use: [
{
loader: 'lit-scss-loader',
options: {
minify: true,
},
}, 'extract-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.css|\.s([ca])ss$/,
exclude: resolve(__dirname, 'src/lib/components'),
use: ['style-loader', 'css-loader', 'sass-loader'],
},
{
test: /\.ts$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
{
loader: 'ts-loader',
},
],
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
plugins: [
new HtmlWebpackPlugin({
template: resolve(__dirname, 'src/templates/index.html'),
filename: 'index.html',
inject: true,
chunks: ['main', 'polyfill_head'],
}),
new HtmlWebpackInjector(),
new CopyWebpackPlugin({
patterns: [
...polyfills,
{
from: resolve(__dirname, 'src/public/'),
to: resolve(__dirname, 'dist/'),
},
],
}),
new ImageminWebpackPlugin({
plugins: [
ImageminMozjpeg({
quality: 50,
progressive: true,
}),
],
}),
],
};