2018-07-05 09:54:41 +00:00
|
|
|
const common = require('./webpack.common.js')
|
2018-07-05 16:01:01 +00:00
|
|
|
const WorkboxPlugin = require('workbox-webpack-plugin')
|
2018-10-18 14:36:30 +00:00
|
|
|
const PrerenderSPAPlugin = require('prerender-spa-plugin')
|
|
|
|
const Renderer = PrerenderSPAPlugin.PuppeteerRenderer
|
|
|
|
const path = require('path')
|
|
|
|
const cheerio = require('cheerio')
|
|
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
2018-03-01 18:39:36 +00:00
|
|
|
|
2018-10-18 14:36:30 +00:00
|
|
|
const prerenderConfig = () => ({
|
|
|
|
staticDir: path.resolve('dist'),
|
|
|
|
renderer: new Renderer({
|
|
|
|
renderAfterTime: 5000,
|
|
|
|
skipThirdPartyRequests: true
|
|
|
|
}),
|
|
|
|
postProcess: context => {
|
|
|
|
const $ = cheerio.load(context.html)
|
|
|
|
// force https on twitter emoji cdn
|
|
|
|
$('img[src^="http://twemoji.maxcdn.com"]').each((i, el) => {
|
|
|
|
$(el).attr('src', (_, path) => path.replace('http://', 'https://'))
|
|
|
|
})
|
|
|
|
// Remove loader
|
|
|
|
$('#outdated-browser').after(`
|
|
|
|
<style>
|
|
|
|
#js {
|
|
|
|
opacity: 1;
|
|
|
|
transform: translateY(0px);
|
|
|
|
}
|
|
|
|
#lds-ellipsis {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
`)
|
|
|
|
// Remove piwik script
|
|
|
|
$('script[src$="stats.data.gouv.fr/piwik.js"]').remove()
|
|
|
|
context.html = $.html()
|
|
|
|
return context
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// Replace style-loader with MiniCssExtractPlugin.loader
|
|
|
|
common.module.rules
|
|
|
|
.find(rule => rule.test.test('a.css'))
|
2018-11-08 13:22:02 +00:00
|
|
|
.use.find(loader => (loader || loader.loader) === 'style-loader').loader =
|
2018-10-18 14:36:30 +00:00
|
|
|
MiniCssExtractPlugin.loader
|
2018-03-01 18:39:36 +00:00
|
|
|
module.exports = {
|
|
|
|
...common,
|
2018-03-12 15:37:23 +00:00
|
|
|
mode: 'production',
|
2018-08-28 09:53:07 +00:00
|
|
|
devtool: 'source-map',
|
2018-07-05 16:01:01 +00:00
|
|
|
plugins: [
|
2018-10-18 14:36:30 +00:00
|
|
|
new MiniCssExtractPlugin({
|
|
|
|
// Options similar to the same options in webpackOptions.output
|
|
|
|
// both options are optional
|
|
|
|
filename: '[name].[hash].css',
|
|
|
|
chunkFilename: '[id].[hash].css'
|
|
|
|
}),
|
2018-07-05 09:54:41 +00:00
|
|
|
...common.plugins,
|
2018-07-05 16:01:01 +00:00
|
|
|
new WorkboxPlugin.GenerateSW({
|
|
|
|
clientsClaim: true,
|
|
|
|
skipWaiting: true,
|
|
|
|
swDest: 'sw.js',
|
|
|
|
runtimeCaching: [
|
|
|
|
{
|
|
|
|
urlPattern: new RegExp(
|
|
|
|
'https://fonts.(?:googleapis|gstatic).com/(.*)|https://cdn.polyfill.io/v2/polyfill.min.js'
|
|
|
|
),
|
|
|
|
handler: 'cacheFirst',
|
|
|
|
options: {
|
|
|
|
cacheName: 'google-fonts',
|
|
|
|
expiration: {
|
|
|
|
maxEntries: 5
|
|
|
|
},
|
|
|
|
cacheableResponse: {
|
|
|
|
statuses: [0, 200]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-18 14:36:30 +00:00
|
|
|
],
|
|
|
|
navigateFallback: '/fallback',
|
|
|
|
navigateFallbackBlacklist: [
|
|
|
|
/.*\?s=.*$/,
|
|
|
|
/^\/stats/,
|
|
|
|
/^\/robots\.txt$/,
|
|
|
|
/^\/sitemap\.infrance\.txt$/
|
2018-07-05 16:01:01 +00:00
|
|
|
]
|
2018-10-18 14:36:30 +00:00
|
|
|
}),
|
|
|
|
new PrerenderSPAPlugin({
|
|
|
|
...prerenderConfig(),
|
|
|
|
outputDir: path.resolve('dist', 'prerender', 'infrance'),
|
|
|
|
routes: ['/', '/social-security'],
|
|
|
|
indexPath: path.resolve('dist', 'infrance.html')
|
|
|
|
}),
|
|
|
|
new PrerenderSPAPlugin({
|
|
|
|
...prerenderConfig(),
|
|
|
|
outputDir: path.resolve('dist', 'prerender', 'embauche'),
|
|
|
|
routes: ['/'],
|
|
|
|
indexPath: path.resolve('dist', 'embauche.html')
|
2018-07-05 16:01:01 +00:00
|
|
|
})
|
2018-07-05 09:54:41 +00:00
|
|
|
]
|
2018-03-01 18:39:36 +00:00
|
|
|
}
|