This repository has been archived by the owner on Aug 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(build): replace rollup with webpack to make build faster
We replace `rollup` with `webpack` to make our builds faster. While webpack is not faster without a cache it supports persistent caches in the file system which makes it significantly faster in development. Webpack is also significantly faster in watch mode. On my machine a rollup build and a webpack build without a cache take about 60 seconds. If a cache is present webpack builds the project in 8-9 seconds. When updating a file in watch mode rollup takes 7-8 seconds to rebuild. Webpack rebuilds the project in under a second. Another thing to note is that in the past I spent multiple hours investigating issues with rollup and tweaking the config. None of this was necessary for webpack. We also gain more functionality, for example we can now leverage templating in the HTML document. Some implementation notes: * We patch `package.json` of `svelte-persistent-store` because of [this issue][sps-issue]. This only worked before because rollup itself was buggy. * We add some dependencies that are used in our source code but were not explicitly specified. * We use `html-webpack-plugin` to dynamically build `public/index.html` and configure it for different environments. * We remove `bundle.css`. CSS is now injected during runtime via JS. Follup-up: * We still need to leverage the webpack cache on CI [sps-issue]: andsala/svelte-persistent-store#15 Signed-off-by: Thomas Scholtes <thomas@monadic.xyz>
- Loading branch information
Thomas Scholtes
committed
Mar 25, 2021
1 parent
6ec277f
commit 6f90358
Showing
9 changed files
with
1,191 additions
and
511 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
diff --git a/node_modules/svelte-persistent-store/package.json b/node_modules/svelte-persistent-store/package.json | ||
index 115449e..2d2999d 100644 | ||
--- a/node_modules/svelte-persistent-store/package.json | ||
+++ b/node_modules/svelte-persistent-store/package.json | ||
@@ -11,10 +11,6 @@ | ||
"homepage": "https://github.com/andsala/svelte-persistent-store", | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
- "exports": { | ||
- ".": "./dist/index.js", | ||
- "./": "./dist/" | ||
- }, | ||
"types": "dist/**", | ||
"scripts": { | ||
"build": "tsup src/local.ts src/session.ts src/index.ts --external svelte --format esm,cjs --inlineDynamicImports --dts", |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import path from "path"; | ||
import sveltePreprocess from "svelte-preprocess"; | ||
import webpack from "webpack"; | ||
import HtmlWebpackPlugin from "html-webpack-plugin"; | ||
|
||
interface Argv { | ||
mode?: "production" | "development"; | ||
} | ||
|
||
const tsRule = { | ||
test: /\.ts$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: "ts-loader", | ||
options: { | ||
compilerOptions: { | ||
noEmit: false, | ||
module: "es6", | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
function electronMain(_env: unknown, argv: Argv): webpack.Configuration { | ||
const mode = argv.mode || "development"; | ||
return { | ||
name: "main", | ||
entry: "./native/index.ts", | ||
mode, | ||
cache: { | ||
type: "filesystem", | ||
}, | ||
externals: ["fsevents"], | ||
target: "electron-main", | ||
externalsPresets: { electronMain: true, node: true }, | ||
module: { | ||
rules: [tsRule], | ||
}, | ||
resolve: { | ||
extensions: [".ts", ".js"], | ||
}, | ||
output: { | ||
filename: "bundle.js", | ||
path: path.resolve(__dirname, "native"), | ||
}, | ||
optimization: { | ||
minimize: false, | ||
}, | ||
}; | ||
} | ||
|
||
function ui(_env: unknown, argv: Argv): webpack.Configuration { | ||
const mode = argv.mode || "development"; | ||
const isProduction = mode === "production"; | ||
return { | ||
name: "ui", | ||
entry: "./ui/index.ts", | ||
mode, | ||
devtool: isProduction ? "source-map" : "eval-source-map", | ||
cache: { | ||
type: "filesystem", | ||
}, | ||
performance: { | ||
hints: false, | ||
}, | ||
target: "web", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.svelte$/, | ||
use: { | ||
loader: "svelte-loader", | ||
options: { | ||
compilerOptions: { dev: !isProduction }, | ||
preprocess: sveltePreprocess(), | ||
}, | ||
}, | ||
}, | ||
tsRule, | ||
], | ||
}, | ||
resolve: { | ||
fallback: { | ||
crypto: require.resolve("crypto-browserify"), | ||
stream: require.resolve("stream-browserify"), | ||
}, | ||
extensions: [".svelte", ".ts", ".js"], | ||
}, | ||
output: { | ||
filename: "bundle.js", | ||
path: path.resolve(__dirname, "public"), | ||
}, | ||
plugins: [ | ||
new webpack.ProvidePlugin({ | ||
process: "process", | ||
}), | ||
new HtmlWebpackPlugin({ | ||
template: "ui/index.html", | ||
meta: { | ||
"Content-Security-Policy": { | ||
"http-equiv": "Content-Security-Policy", | ||
content: isProduction | ||
? "script-src 'self'" | ||
: "script-src 'self' 'unsafe-eval'", | ||
}, | ||
}, | ||
}), | ||
], | ||
}; | ||
} | ||
|
||
export default [ui, electronMain]; |
Oops, something went wrong.