Fix Tauri build
This isn't working, but has some attempts. It's currently blocked, because the built app just has many `ReferenceError: Can't find variable: process`. Something with Webpack isn't building properly, as even trying to just run `webpack serve` from inside yields the same result (I updated webpack, but the problem is in the setup/config, really). I also tried setting `resolve.fallback.process: require.resolve('process/browser')` ([among other things](https://pretagteam.com/question/webpack-5-uncaught-referenceerror-process-is-not-defined)), but the executed code comes from `@padloc/app`, so I'd have to add that package there, and it feels wrong. I'm positive I'm just doing something wrong with the setup, but already spent quite some time on it.
To test, pull this down, run `npm install`, and `npm run tauri:dev` (runs with `webpack` instead of `tauri`, just because the console errors are more useful).
In the process of trying to get this to work, I migrated the icons to the assets directory and updated them. I also tweaked the initial HTML to match the new v4 theme.
Related to #281
2021-12-27 10:43:39 +00:00
const { resolve , join } = require ( "path" ) ;
2021-12-28 12:59:40 +00:00
const { EnvironmentPlugin , optimize } = require ( "webpack" ) ;
2020-07-19 15:50:05 +00:00
const HtmlWebpackPlugin = require ( "html-webpack-plugin" ) ;
const { CleanWebpackPlugin } = require ( "clean-webpack-plugin" ) ;
const { version } = require ( "./package.json" ) ;
2021-12-26 09:38:28 +00:00
const out = process . env . PL _PWA _DIR || resolve ( _ _dirname , "dist" ) ;
2020-07-19 15:50:05 +00:00
const serverUrl = process . env . PL _SERVER _URL || ` http://0.0.0.0: ${ process . env . PL _SERVER _PORT || 3000 } ` ;
2022-05-16 15:03:18 +00:00
const pwaUrl = process . env . PL _PWA _URL || ` http://localhost: ${ process . env . PL _PWA _PORT || 8080 } ` ;
2022-05-16 15:25:46 +00:00
const websocketPwaUrl = pwaUrl . replace ( "http://" , "ws://" ) . replace ( "https://" , "wss://" ) ;
2021-12-26 09:38:28 +00:00
const rootDir = resolve ( _ _dirname , "../.." ) ;
const assetsDir = resolve ( rootDir , process . env . PL _ASSETS _DIR || "assets" ) ;
2022-01-31 11:02:35 +00:00
const { name , terms _of _service } = require ( join ( assetsDir , "manifest.json" ) ) ;
2020-07-19 15:50:05 +00:00
module . exports = {
2021-12-26 09:38:28 +00:00
entry : resolve ( _ _dirname , "src/index.ts" ) ,
2020-07-19 15:50:05 +00:00
output : {
path : out ,
filename : "[name].js" ,
chunkFilename : "[name].chunk.js" ,
2021-06-28 16:08:34 +00:00
publicPath : "/" ,
2020-07-19 15:50:05 +00:00
} ,
mode : "development" ,
devtool : "source-map" ,
stats : "minimal" ,
resolve : {
2021-12-26 09:38:28 +00:00
extensions : [ ".ts" , ".js" , ".css" , ".svg" , ".png" , ".jpg" ] ,
alias : {
assets : assetsDir ,
} ,
2020-07-19 15:50:05 +00:00
} ,
module : {
rules : [
{
test : /\.ts$/ ,
2021-06-28 16:08:34 +00:00
loader : "ts-loader" ,
2020-07-19 15:50:05 +00:00
} ,
{
test : /\.css$/ ,
2021-06-28 16:08:34 +00:00
use : [ "style-loader" , "css-loader" ] ,
2020-07-19 15:50:05 +00:00
} ,
{
test : /\.(woff|woff2|eot|ttf|otf|svg)$/ ,
2021-06-28 16:08:34 +00:00
use : [ "file-loader" ] ,
} ,
2021-12-26 09:38:28 +00:00
{
test : /\.txt|md$/i ,
use : "raw-loader" ,
} ,
2021-06-28 16:08:34 +00:00
] ,
2020-07-19 15:50:05 +00:00
} ,
plugins : [
new EnvironmentPlugin ( {
2021-12-27 12:26:54 +00:00
PL _APP _NAME : name ,
2020-07-19 15:50:05 +00:00
PL _SERVER _URL : serverUrl ,
PL _SUPPORT _EMAIL : "support@padloc.app" ,
PL _VERSION : version ,
2022-01-17 17:32:21 +00:00
PL _VENDOR _VERSION : version ,
2021-12-29 10:36:24 +00:00
PL _DISABLE _SW : true ,
2021-12-27 12:26:54 +00:00
PL _CLIENT _SUPPORTED _AUTH _TYPES : "email" ,
2022-01-31 11:02:35 +00:00
PL _TERMS _OF _SERVICE : terms _of _service ,
2020-07-19 15:50:05 +00:00
} ) ,
new CleanWebpackPlugin ( ) ,
new HtmlWebpackPlugin ( {
Fix Tauri build
This isn't working, but has some attempts. It's currently blocked, because the built app just has many `ReferenceError: Can't find variable: process`. Something with Webpack isn't building properly, as even trying to just run `webpack serve` from inside yields the same result (I updated webpack, but the problem is in the setup/config, really). I also tried setting `resolve.fallback.process: require.resolve('process/browser')` ([among other things](https://pretagteam.com/question/webpack-5-uncaught-referenceerror-process-is-not-defined)), but the executed code comes from `@padloc/app`, so I'd have to add that package there, and it feels wrong. I'm positive I'm just doing something wrong with the setup, but already spent quite some time on it.
To test, pull this down, run `npm install`, and `npm run tauri:dev` (runs with `webpack` instead of `tauri`, just because the console errors are more useful).
In the process of trying to get this to work, I migrated the icons to the assets directory and updated them. I also tweaked the initial HTML to match the new v4 theme.
Related to #281
2021-12-27 10:43:39 +00:00
title : name ,
2021-12-26 09:38:28 +00:00
template : resolve ( _ _dirname , "src/index.html" ) ,
2022-03-22 07:03:30 +00:00
meta : {
"Content-Security-Policy" : {
"http-equiv" : "Content-Security-Policy" ,
2022-05-16 15:25:46 +00:00
content : ` default-src 'self' ${ serverUrl } ${ websocketPwaUrl } https://api.pwnedpasswords.com blob:; style-src 'self' 'unsafe-inline'; object-src 'self' blob:; frame-src 'self'; img-src 'self' blob: data: https:; ` ,
2022-03-22 07:03:30 +00:00
} ,
} ,
2021-06-28 16:08:34 +00:00
} ) ,
2021-12-28 12:59:40 +00:00
// NOTE: Right now, tauri will try to add `const __TAURI_INVOKE_KEY__ = randomNumber` to every generated JS file, which causes problems if there are chunks
new optimize . LimitChunkCountPlugin ( {
maxChunks : 1 ,
} ) ,
2020-07-19 15:50:05 +00:00
] ,
devServer : {
historyApiFallback : true ,
host : "0.0.0.0" ,
2021-06-28 16:08:34 +00:00
port : process . env . PL _PWA _PORT || 8080 ,
2021-12-27 12:26:54 +00:00
// hot: false,
// liveReload: false,
client : { overlay : false } ,
2021-06-28 16:08:34 +00:00
} ,
2020-07-19 15:50:05 +00:00
} ;