-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.prod.js
More file actions
123 lines (119 loc) · 3.12 KB
/
Copy pathwebpack.prod.js
File metadata and controls
123 lines (119 loc) · 3.12 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
/** ↓ エディタで補完を効かせるための JSDoc */
/** @type {import('webpack').Configuration} */
// プラグインの読み込み
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const cssnano = require('cssnano');
const path = require('path');
const webpack = require('webpack');
// 環境変数
const environment = process.env.NODE_ENV || 'prod';
const version = `${require('./package.json').version}`;
const filename =
environment === 'prod'
? `axnospaint-lib-${version}.min.js`
: `axnospaint-lib-${environment}-${version}.min.js`;
const outputPath = environment === 'demo' ? 'docs/latest' : 'dist';
// ビルド日時
const buildDate = new Date().toISOString();
module.exports = {
mode: 'production',
resolve: {
alias: {
'@extensions': path.resolve(__dirname, `extensions/${environment}.js`),
},
},
module: {
rules: [
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [
[
cssnano,
{
// コメントを削除する
preset: [
'default',
{ discardComments: { removeAll: true } },
],
},
],
],
},
},
},
],
},
{
test: /\.txt/,
type: 'asset/source',
},
{
test: /\.png/,
type: 'asset/inline',
},
],
},
plugins: [
// プラグインのインスタンスを作成
new HtmlWebpackPlugin({
// テンプレート
template: './src/index.html',
// <script> ~ </script> タグの挿入位置
inject: 'body',
// スクリプト読み込みのタイプ
scriptLoading: 'defer',
// ファビコンも <link rel="shortcut icon" ~ /> として挿入できる
//favicon: "./src/favicon.ico",
}),
new webpack.DefinePlugin({
PACKAGE_VERSION: `"${version}"`,
PACKAGE_DATE: `"${buildDate}"`,
}),
// ビルドファイルの先頭にコメントを挿入
new webpack.BannerPlugin(
`AXNOS Paint version ${version} (${buildDate})\n(c) 2022「悪の巣」部屋番号13番:「趣味の悪い大衆酒場[Mad end dance hall]」\nLicensed under MPL 2.0`,
{
raw: false,
entryOnly: true,
},
),
],
devServer: {
static: {
directory: './dist',
},
},
// メインのJS
entry: {
axnospaint: './src/index.js',
},
// 出力ファイル
output: {
path: path.resolve(__dirname, outputPath),
filename: `${filename}`,
library: {
name: 'AXNOSPaint',
export: 'default',
type: 'umd',
},
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
compress: { drop_console: true },
},
}),
],
},
};