This repository has been archived by the owner on Jun 20, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 115
/
webpack.common.js
153 lines (147 loc) · 3.73 KB
/
webpack.common.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const env = process.env.NODE_ENV ?? 'production';
require('dotenv').config({
path: `.env.${env}`,
});
const path = require('path');
const CopyPlugin = require('copy-webpack-plugin');
const webpack = require('webpack');
const { DefinePlugin } = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
module.exports = function ({
onlyTranspileTypescript = false,
experimentalFeatures = false,
snap = false,
} = {}) {
const moduleConfig = {
rules: [
{
test: /\.ts$/,
use: [
'babel-loader',
{
loader: 'ts-loader',
options: {
transpileOnly: onlyTranspileTypescript,
},
},
],
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
sideEffects: true,
test: /\.(png|html)$/i,
loader: 'file-loader',
options: {
name: '[name].[ext]',
},
},
],
};
const resolve = {
extensions: ['.ts', '.js'],
alias: {
'@web': path.resolve(__dirname, 'web/app/assets/javascripts'),
},
};
const EXPERIMENTAL_FEATURES = JSON.stringify(experimentalFeatures);
const IS_SNAP = JSON.stringify(snap ? true : false);
const electronMainConfig = {
entry: {
index: './app/index.ts',
},
output: {
path: path.resolve(__dirname, 'app', 'dist'),
filename: 'index.js',
},
devtool: 'inline-cheap-source-map',
target: 'electron-main',
node: {
__dirname: false,
},
resolve,
module: moduleConfig,
externals: {
keytar: 'commonjs keytar',
},
optimization: {
minimizer: [
new TerserPlugin({
exclude: ['vendor', 'web', 'node_modules'],
}),
],
},
plugins: [
new DefinePlugin({
EXPERIMENTAL_FEATURES,
IS_SNAP,
}),
new CopyPlugin({
patterns: [
{
from: 'app/vendor',
to: 'vendor',
},
{
from: 'web/dist',
to: 'standard-notes-web',
},
{
from: 'web/public/components',
to: 'standard-notes-web/components',
},
{
from: 'app/node_modules',
to: 'node_modules',
},
{
from: 'app/stylesheets/renderer.css',
to: 'stylesheets/renderer.css',
},
{
from: 'app/icon',
to: 'icon',
},
],
}),
],
};
const electronRendererConfig = {
entry: {
preload: './app/javascripts/Renderer/Preload.ts',
renderer: './app/javascripts/Renderer/Renderer.ts',
grantLinuxPasswordsAccess: './app/javascripts/Renderer/grantLinuxPasswordsAccess.js',
},
output: {
path: path.resolve(__dirname, 'app', 'dist', 'javascripts', 'renderer'),
publicPath: '/',
},
target: 'electron-renderer',
devtool: 'inline-cheap-source-map',
node: {
__dirname: false,
},
resolve,
module: moduleConfig,
externals: {
electron: 'commonjs electron',
},
plugins: [
new webpack.DefinePlugin({
DEFAULT_SYNC_SERVER: JSON.stringify(
process.env.DEFAULT_SYNC_SERVER || 'https://api.standardnotes.com'
),
PURCHASE_URL: JSON.stringify(process.env.PURCHASE_URL),
PLANS_URL: JSON.stringify(process.env.PLANS_URL),
DASHBOARD_URL: JSON.stringify(process.env.DASHBOARD_URL),
EXPERIMENTAL_FEATURES,
WEBSOCKET_URL: JSON.stringify(process.env.WEBSOCKET_URL),
ENABLE_UNFINISHED_FEATURES: JSON.stringify(process.env.ENABLE_UNFINISHED_FEATURES),
}),
],
};
return [electronMainConfig, electronRendererConfig];
};