-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.preview.js
executable file
·68 lines (65 loc) · 2.59 KB
/
webpack.preview.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
const webpack = require('webpack');
const merge = require('webpack-merge');
const common = require('./webpack.nondev.js');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const PrerenderSPAPlugin = require('prerender-spa-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const pretty = require('pretty');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const repoName = 'state-debt';
module.exports = env => {
var folder = env === 'localpreview' ? '/preview/' : '/docs/';
return merge(common(), {
devtool: 'inline-source-map',
plugins: [
new CleanWebpackPlugin([folder.replace(/\//g,'')]),
new HtmlWebpackPlugin({
title: 'A Tool for Better Debt Comparisons',
template: './src/index-dev.html',
}),
new CopyWebpackPlugin([{
from: './**/*.*',
to: './',
context: 'src/-/'
}, {
from: 'assets/**/*.*',
exclude: 'assets/Pew/css/',
context: 'src',
}, {
from: 'assets/Pew/css/*.*',
context: 'src',
transform(content, path) {
if ( env === 'localpreview'){
return content.toString();
} else {
return content.toString().replace(/url\("\/([^/])/g, 'url("/' + repoName + '/$1').replace(/\/pew\//g,'/Pew/'); // this modifies the content of the files being copied; here making sure url('/...') is changed
}
}
}]),
new PrerenderSPAPlugin({
// Required - The path to the webpack-outputted app to prerender.
staticDir: path.join(__dirname, folder),
// Required - Routes to render.
routes: ['/'],
renderer: new PrerenderSPAPlugin.PuppeteerRenderer({
injectProperty: 'IS_PRERENDERING',
inject: true,
renderAfterTime: 1000
}),
postProcess: function(renderedRoute){
renderedRoute.html = pretty(renderedRoute.html);
return renderedRoute;
}
}),
new webpack.EnvironmentPlugin({
'NODE_ENV': env
})
],
output: {
filename: '[name].js',
path: path.join(__dirname, folder),
}
});
};