-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.js
106 lines (103 loc) · 3.37 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
const path = require('path');
const fs = require('fs');
const CopyPlugin = require('copy-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const { SourceMapDevToolPlugin } = require('webpack');
const config = {
entry: {
'main': './src/viewer.js',
'pdf.worker': 'pdfjs-dist/lib/pdf.worker.js',
},
module: {
rules: [
{
test: /\.m?js/,
resolve: {
fullySpecified: false
}
},
{
test: /\.(m?js)$/,
exclude: new RegExp('node_modules\\'+path.sep+'(?!@guardtime/ksi-js-api|@guardtime/gt-js-common).*'),
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
corejs: 3,
targets: '> 0.25%',
useBuiltIns: 'usage'
}]
],
plugins: ["@babel/plugin-proposal-class-properties"]
}
}
},
{
test: /\.css$/i,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(svg|cur|png|gif)$/i,
use: ['file-loader'],
},
]
},
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist')
},
resolve: {
modules: ['node_modules'],
alias: {
[path.resolve(__dirname, 'node_modules/pdfjs-dist/lib/core/annotation.js')]:
path.resolve(__dirname, 'src/annotation.js'),
[path.resolve(__dirname, 'node_modules/pdfjs-dist/lib/external/webL10n/l10n/')]:
path.resolve(__dirname, 'node_modules/pdf.js/external/webL10n/l10n/')
},
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: 'index.html',
favicon: 'favicon.ico',
inject: 'head'
},),
new NodePolyfillPlugin()
]
};
function addKsiTranslations(content, filePath) {
const locale = filePath.split('/').slice(-2)[0];
if (['et', 'en-CA', 'en-GB', 'en-US', 'en-ZA'].includes(locale)) {
return content + fs.readFileSync(path.resolve(__dirname, 'src/locale/' + locale + '/viewer.properties'));
}
return content;
}
module.exports = (env, argv) => {
const defaultConfig = process.env.PDF_CONFIG || 'static/default_configuration.json';
if (argv.mode === 'development') {
config.plugins.push(new SourceMapDevToolPlugin());
config.plugins.push(
new CopyPlugin({ patterns: [
{ from: defaultConfig, to:"static/default_configuration.json"},
{ from: 'demo/signed.pdf', to: 'demo' },
{ from: 'node_modules/pdfjs-dist/cmaps/', to: 'cmaps' },
{ from: 'node_modules/pdf.js/l10n/', to: 'locale', transform(content, path) { return addKsiTranslations(content, path); }},
{ from: 'src/locale/locale.properties', to: 'locale'}
]}),
)
}
if (argv.mode === 'production') {
config.plugins.push(
new CopyPlugin({ patterns: [
{ from: 'static/readonly_configuration.json', to:"static/default_configuration.json"},
{ from: 'node_modules/pdfjs-dist/cmaps/', to: 'cmaps' },
{ from: 'node_modules/pdf.js/l10n/', to: 'locale', transform(content, path) { return addKsiTranslations(content, path); }},
{ from: 'src/locale/locale.properties', to: 'locale'}
]}),
)
}
return config;
};