-
Notifications
You must be signed in to change notification settings - Fork 247
/
Copy pathwebpack.renderer.js
102 lines (93 loc) · 3.58 KB
/
webpack.renderer.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const path = require('path');
const fsExtra = require('fs-extra');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const makeConfig = require('./webpack.makeConfig.js');
const getModulePath = moduleName => path.dirname(require.resolve(`${moduleName}`));
const generateIndexFile = template => {
let html = template;
html = html.replace(
'</head>', '<script>require("source-map-support/source-map-support.js").install()</script></head>'
);
const filePath = path.join('dist', '.renderer-index-template.html');
fsExtra.outputFileSync(filePath, html);
return `!!html-loader?minimize=false&attributes=false!${filePath}`;
};
const template = fsExtra.readFileSync('src/renderer/index.html', {encoding: 'utf8'});
module.exports = makeConfig(
{
target: 'electron-renderer',
entry: {
renderer: './src/renderer/index.js'
},
context: path.resolve(__dirname),
externals: [
'source-map-support',
'electron',
'webpack'
],
output: {
filename: '[name].js',
assetModuleFilename: 'static/assets/[name].[hash][ext]',
chunkFilename: '[name].bundle.js',
libraryTarget: 'commonjs2',
path: path.resolve(__dirname, 'dist/renderer')
},
module: {
rules: [
{
test: /\.node$/,
use: 'node-loader'
},
{
test: /\.(html)$/,
use: {loader: 'html-loader'}
}
]
}
},
{
name: 'renderer',
useReact: true,
disableDefaultRulesForExtensions: ['js', 'jsx', 'css', 'svg', 'png', 'wav', 'gif', 'jpg', 'ttf'],
babelPaths: [
path.resolve(__dirname, 'src', 'renderer'),
/node_modules[\\/]+@scratch[\\/]+[^\\/]+[\\/]+src/,
/node_modules[\\/]+pify/,
/node_modules[\\/]+@vernier[\\/]+godirect/
],
plugins: [
new HtmlWebpackPlugin({
filename: 'index.html',
template: generateIndexFile(template),
minify: false
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(getModulePath('@scratch/scratch-gui'), 'static'),
to: 'static'
},
{
from: 'extension-worker.{js,js.map}',
context: getModulePath('@scratch/scratch-gui')
},
{
from: path.join(getModulePath('@scratch/scratch-gui'), 'libraries'),
to: 'static/libraries',
flatten: true
}
// This still results in a missing fetch worker error, because the fetch-worker
// is attempted to be resolved on an absolute path (e.g. file:///chunks/fetch-worker..)
// That is still fine, because we don't need the fetch-worker to retrieve information.
// TODO: For a long term fix, change how the fetch-worker is resolved in `scratch-storage`
// {
// context: getModulePath('@scratch/scratch-gui'),
// from: 'chunks/fetch-worker.*.{js,js.map}',
// noErrorOnMissing: true
// }
]
})
]
}
);