forked from Automattic/wp-calypso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.desktop.js
101 lines (98 loc) · 2.96 KB
/
webpack.config.desktop.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
const path = require( 'path' );
const TranspileConfig = require( '@automattic/calypso-build/webpack/transpile' );
const { shouldTranspileDependency } = require( '@automattic/calypso-build/webpack/util' );
const webpack = require( 'webpack' );
const cacheIdentifier = require( '../build-tools/babel/babel-loader-cache-identifier' );
const { workerCount } = require( './webpack.common' );
const isDevelopment = process.env.NODE_ENV === 'development';
const cacheDirectory = path.resolve( '.cache', 'babel-desktop' );
module.exports = {
entry: path.join( __dirname, 'desktop' ),
output: {
path: path.resolve( 'desktop/build' ),
filename: 'desktop.js',
chunkFilename: 'desktop.[name].js',
libraryTarget: 'commonjs2',
},
target: 'electron-main',
mode: isDevelopment ? 'development' : 'production',
module: {
rules: [
{
include: path.join( __dirname, 'sections.js' ),
use: {
loader: path.join( __dirname, '../build-tools/webpack/sections-loader' ),
options: { useRequire: true, onlyIsomorphic: true },
},
},
{
test: /\.html$/,
loader: 'html-loader',
},
TranspileConfig.loader( {
workerCount,
configFile: path.resolve( 'babel.config.js' ),
cacheDirectory,
cacheIdentifier,
cacheCompression: false,
exclude: /node_modules\//,
} ),
TranspileConfig.loader( {
workerCount,
presets: [ require.resolve( '@automattic/calypso-build/babel/dependencies' ) ],
cacheDirectory,
cacheIdentifier,
cacheCompression: false,
include: shouldTranspileDependency,
} ),
{
test: /\.(sc|sa|c)ss$/,
loader: 'ignore-loader',
},
{
test: /\.(?:gif|jpg|jpeg|png|svg)$/i,
use: {
loader: 'file-loader',
options: {
name: '[name]-[hash].[ext]',
outputPath: 'images',
publicPath: '/calypso/images/',
emitFile: false,
},
},
},
],
},
node: {
__filename: true,
__dirname: true,
},
externals: [
'webpack',
'keytar',
// These are Calypso server modules we don't need, so let's not bundle them
'webpack.config',
],
resolve: {
extensions: [ '.json', '.js', '.jsx', '.ts', '.tsx' ],
mainFields: [ 'calypso:src', 'module', 'main' ],
modules: [ __dirname, 'node_modules' ],
alias: {
config: 'calypso/server/config',
'@automattic/calypso-config': 'calypso/server/config',
// Alias calypso to ./client. This allows for smaller bundles, as it ensures that
// importing `./client/file.js` is the same thing than importing `calypso/file.js`
calypso: __dirname,
},
},
plugins: [
// The `formidable` package (used by `superagent`) contains conditional code that hijacks
// the `require` function. That breaks webpack.
new webpack.DefinePlugin( { 'global.GENTLY': false } ),
new webpack.NormalModuleReplacementPlugin(
/^calypso[/\\]my-sites[/\\]themes[/\\]theme-upload$/,
'calypso/components/empty-component'
), // Depends on BOM
new webpack.IgnorePlugin( /^\.\/locale$/, /moment$/ ), // server doesn't use moment locales
],
};