generate manifest and compress images

This commit is contained in:
notgne2 2019-12-19 16:31:26 -07:00
parent 37b43fb216
commit 4dc7d943ec
3 changed files with 1942 additions and 138 deletions

View File

@ -1,14 +1,16 @@
{
"dependencies": {
"copy-webpack-plugin": "^5.1.0",
"copy-webpack-plugin": "^5.1.1",
"elm-webpack-loader": "^6.0.1",
"html-webpack-plugin": "^3.2.0",
"imagemin-webpack-plugin": "^2.4.2",
"jsdom": "^15.2.1",
"prerender-spa-plugin": "^3.4.0",
"tempy": "^0.3.0",
"terser-webpack-plugin": "^2.3.0",
"webpack": "^4.41.2",
"terser-webpack-plugin": "^2.3.1",
"webpack": "^4.41.4",
"webpack-cli": "^3.3.10",
"webpack-manifest-plugin": "^2.2.0",
"workbox-webpack-plugin": "^4.3.1"
},
"name": "wand-front-utils",

1932
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,8 @@ const PrerenderSPAPlugin = require('prerender-spa-plugin')
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer
const CopyPlugin = require('copy-webpack-plugin')
const { InjectManifest } = require('workbox-webpack-plugin')
const ManifestPlugin = require('webpack-manifest-plugin')
const ImageminPlugin = require('imagemin-webpack-plugin').default
const { JSDOM } = require('jsdom')
const tempy = require('tempy')
const fs = require('fs')
@ -27,77 +29,83 @@ const jsMin = {
mangle: true,
}
module.exports =
{
output: {
filename: "main.js",
path: path.join(__dirname, "dist"),
publicPath: "/"
},
module: {
rules: [{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
loader: 'elm-webpack-loader',
options: {
optimize: true
}
}],
},
plugins: [
new TerserPlugin({
terserOptions: jsMin,
}),
new HtmlWebpackPlugin({
hash: true,
meta: {
viewport: 'width=device-width, initial-scale=1'
}
}),
new CopyPlugin([{ from: 'data', to: 'data' }, { from: 'wand.js', to: 'wand.js' }]),
new PrerenderSPAPlugin({
staticDir: path.join(__dirname, 'dist'),
routes: ROUTES,
minify: {
minifyCSS: {
compatibility: 'ie9',
level: 2
},
minifyJS: jsMin,
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeComments: true,
sortAttributes: true,
sortClassName: true,
module.exports = {
output: {
filename: "main.js",
path: path.join(__dirname, "dist"),
publicPath: "/"
},
module: {
rules: [{
test: /\.elm$/,
exclude: [/elm-stuff/, /node_modules/],
loader: 'elm-webpack-loader',
options: {
optimize: true
}
}],
},
plugins: [
new ManifestPlugin(),
new ImageminPlugin({
disable: false,
pngquant: {
quality: '95-100'
}
}),
new TerserPlugin({
terserOptions: jsMin,
}),
new HtmlWebpackPlugin({
hash: true,
meta: {
viewport: 'width=device-width, initial-scale=1'
}
}),
new CopyPlugin([{ from: 'data', to: 'data' }, { from: 'wand.js', to: 'wand.js' }]),
new PrerenderSPAPlugin({
staticDir: path.join(__dirname, 'dist'),
routes: ROUTES,
minify: {
minifyCSS: {
compatibility: 'ie9',
level: 2
},
renderer: new Renderer({
renderAfterTime: 500,
}),
postProcess(renderedRoute) {
const dom = new JSDOM(renderedRoute.html, { runScripts: 'outside-only' })
dom.window.eval(`
minifyJS: jsMin,
collapseBooleanAttributes: true,
collapseWhitespace: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
removeComments: true,
sortAttributes: true,
sortClassName: true,
},
renderer: new Renderer({
renderAfterTime: 500,
}),
postProcess(renderedRoute) {
const dom = new JSDOM(renderedRoute.html, { runScripts: 'outside-only' })
dom.window.eval(`
const wandTarget = document.createElement('script')
wandTarget.src = '/wand.js'
document.body.appendChild(wandTarget)
`)
return {
...renderedRoute,
html: dom.serialize(),
}
},
}),
new InjectManifest({
importWorkboxFrom: 'local',
swSrc: magicFile(`
return {
...renderedRoute,
html: dom.serialize(),
}
},
}),
new InjectManifest({
importWorkboxFrom: 'local',
swSrc: magicFile(`
workbox.routing.registerNavigationRoute('/index.html');
workbox.precaching.precacheAndRoute(self.__precacheManifest);
`),
swDest: 'sw.js',
}),
]
}
swDest: 'sw.js',
}),
]
}