-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
120 lines (107 loc) · 2.49 KB
/
webpack.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const pkg = require('./package.json');
const configCommon = {
module: {
rules: [
{
test: /\.ts$/,
use: ['ts-loader'],
exclude: /node_modules/,
},
{
test: /\.(less|css)$/i,
use: [MiniCssExtractPlugin.loader, 'css-loader', 'less-loader'],
},
{
test: /\.(woff2?|png)$/i,
type: 'asset/resource',
generator: {
filename: (pathData) => {
const name = path.basename(
pathData.module.resourceResolveData.relativePath,
);
return `./assets/${name
.replace('.var', '-var')
.toLowerCase()}`;
},
},
},
],
},
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
},
resolve: {
extensions: ['.ts', '.js'],
},
};
const configMain = (env, argv) => {
const isDevMode = argv.mode === 'development';
const config = Object.assign({}, configCommon, {
entry: { 'image-refractor': './src/index.ts' },
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new webpack.BannerPlugin({
banner: () => {
const year = new Date().getFullYear();
return `Image Refractor ${pkg.version}, (c) ${year} ${pkg.author}, ${pkg.license} license`;
},
raw: false,
}),
],
});
if (isDevMode) {
console.log('Development Mode');
return Object.assign({}, config, {
devServer: {
static: './dist',
},
devtool: 'inline-source-map',
});
}
console.log('Production Mode');
return config;
};
const configDemo = (env, argv) => {
const isDevMode = argv.mode === 'development';
const config = Object.assign({}, configCommon, {
entry: { demo: './demo/index.ts' },
output: {
filename: isDevMode ? '[name].[hash].js' : '[name].js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
}),
new HtmlWebpackPlugin({
hash: true,
template: 'demo/index.html',
scriptLoading: 'defer',
inject: 'head',
minify: false,
favicon: 'assets/favicon.svg',
}),
new CopyPlugin({
patterns: [{ from: './assets/*.png', to: './' }],
}),
],
resolve: {
extensions: ['.ts', '.js'],
},
});
return config;
};
module.exports = [configMain, configDemo];