@@ -10,7 +10,7 @@ const path = require('path')
1010const rimraf = require ( 'rimraf' )
1111const chalk = require ( 'chalk' )
1212const webpack = require ( 'webpack' )
13- const ManifestPlugin = require ( 'webpack-manifest-plugin' )
13+ const { WebpackManifestPlugin } = require ( 'webpack-manifest-plugin' )
1414const rehypeSlugPlugin = require ( 'rehype-slug' )
1515const packageJSON = require ( '../package.json' )
1616
@@ -26,15 +26,12 @@ const shared = {
2626 loader : 'babel-loader'
2727 } ,
2828
29- // Transform static file imports into URL strings
30- staticFiles : ( mode ) => ( {
29+ // Transform static file imports into URL strings using Webpack 5 Asset Modules
30+ // https://webpack.js.org/guides/asset-modules/
31+ staticFiles : {
3132 test : / \. ( p n g | j p e ? g | g i f | s v g | w o f f 2 ? | m p 3 | m p 4 | w e b m | w e b p ) $ / ,
32- loader : 'file-loader' ,
33- options : {
34- name : '[path][name].[contenthash].[ext]' ,
35- publicPath : `${ mode === 'production' ? packageJSON . tropical . siteURL : '' } /`
36- }
37- } ) ,
33+ type : 'asset/resource'
34+ } ,
3835
3936 // Transform MDX files into React components.
4037 mdx : {
@@ -52,10 +49,11 @@ const shared = {
5249 }
5350 } ,
5451
55- output : {
52+ output : ( mode ) => ( {
5653 path : path . resolve ( __dirname , '../output' ) ,
57- publicPath : '/'
58- }
54+ publicPath : `${ mode === 'production' ? packageJSON . tropical . siteURL : '' } /` ,
55+ assetModuleFilename : 'assets/[name].[contenthash][ext]'
56+ } )
5957}
6058
6159/*
@@ -70,16 +68,16 @@ const clientConfig = mode => {
7068 module : {
7169 rules : [
7270 shared . rules . js ,
73- shared . rules . staticFiles ( mode ) ,
71+ shared . rules . staticFiles ,
7472 shared . rules . mdx
7573 ]
7674 } ,
7775 output : {
78- ...shared . output ,
76+ ...shared . output ( mode ) ,
7977 filename : mode === 'production' ? '[name].bundle.[contenthash].js' : '[name].bundle.js'
8078 } ,
8179 plugins : [
82- new ManifestPlugin ( {
80+ new WebpackManifestPlugin ( {
8381 fileName : 'manifest.client.json'
8482 } )
8583 ]
@@ -104,19 +102,19 @@ const prerenderConfig = (mode) => {
104102 module : {
105103 rules : [
106104 shared . rules . js ,
107- shared . rules . staticFiles ( mode ) ,
105+ shared . rules . staticFiles ,
108106 shared . rules . mdx
109107 ]
110108 } ,
111109 output : {
112- ...shared . output ,
110+ ...shared . output ( mode ) ,
113111 filename : '[name].bundle.js' ,
114112 libraryExport : 'default' ,
115113 libraryTarget : 'commonjs2' ,
116114 library : 'prerender'
117115 } ,
118116 plugins : [
119- new ManifestPlugin ( {
117+ new WebpackManifestPlugin ( {
120118 fileName : 'manifest.prerender.json'
121119 } )
122120 ]
@@ -177,7 +175,7 @@ rimraf(path.resolve(__dirname, '../output/*'), err => {
177175 console . log ( chalk . cyan ( '🏝 Clearing commonjs require cache...' ) )
178176 delete require . cache [ require . resolve ( prerenderModulePath ) ]
179177 console . log ( chalk . cyan ( '🏝 Loading webpacked prerender module...' ) )
180- const prerender = require ( prerenderModulePath )
178+ const { prerender } = require ( prerenderModulePath )
181179 console . log ( chalk . cyan ( '🏝 Prerendering...' ) )
182180
183181 try {
0 commit comments