-
Notifications
You must be signed in to change notification settings - Fork 33
/
preview.ts
89 lines (87 loc) · 2.99 KB
/
preview.ts
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
// @ts-ignore
import MiniHtmlWebpackPlugin from 'mini-html-webpack-plugin';
import * as path from 'path';
import webpack from 'webpack';
// @ts-ignore
import { GenerateSW } from 'workbox-webpack-plugin';
import { Stage } from '../types';
import { common } from './common';
import { plugins } from './plugins';
const APP_ROOT_DIR = path.resolve(__dirname, '..', '..', '..');
const DIST_DIR = path.resolve(APP_ROOT_DIR, 'dist', 'preview');
const EDITOR_PACKAGE = path.resolve(APP_ROOT_DIR, 'packages', 'neo-one-editor');
export const preview = ({ stage }: { readonly stage: Stage }): webpack.Configuration => ({
...common({ stage, bundle: 'preview' }),
entry: path.resolve(EDITOR_PACKAGE, 'src', 'preview', 'window', 'entry.tsx'),
output: {
path: DIST_DIR,
filename: stage === 'dev' ? '[name].js' : '[name].[hash:8].js',
chunkFilename: stage === 'dev' ? '[name].js' : 'preview.[name].[chunkHash:8].js',
},
plugins: [
new MiniHtmlWebpackPlugin({
context: {
title: 'NEO•ONE Preview',
},
// tslint:disable-next-line no-any
template: ({ css, js, title, publicPath }: any) =>
`<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>${title}</title>
${MiniHtmlWebpackPlugin.generateCSSReferences({ files: css, publicPath })}
<style>
body {
margin: 0;
background-color: #F8F5FD;
text-rendering: optimizeLegibility;
}
</style>
</head>
<body>
<div id="app"></div>
${MiniHtmlWebpackPlugin.generateJSReferences({ files: js, publicPath })}
</body>
</html>`,
}),
]
.concat(plugins({ stage, bundle: 'preview' }))
.concat(
process.env.NEO_ONE_DISABLE_SW === 'true'
? []
: [
new GenerateSW({
swDest: 'sw.js',
include: [/.(js|css|html|woff|woff2|json|png|svg|wasm)$/],
clientsClaim: true,
runtimeCaching: [
{
urlPattern: /^https:\/\/.*.jsdelivr.com/,
handler: 'CacheFirst',
options: {
cacheName: 'jsdelivr',
expiration: {
maxEntries: 100000,
purgeOnQuotaError: true,
},
cacheableResponse: {
statuses: [0, 200],
},
matchOptions: {
ignoreSearch: true,
},
},
},
],
...(stage === 'prod'
? {
globDirectory: DIST_DIR,
globPatterns: ['**/*.{js,css,html,woff,woff2,json,png,svg,wasm}'],
maximumFileSizeToCacheInBytes: 50 * 1024 * 1024,
}
: {}),
}),
],
),
});