Skip to content

Commit

Permalink
Configure library and demo for production builds
Browse files Browse the repository at this point in the history
  • Loading branch information
david-yz-liu committed Apr 16, 2024
1 parent 4d72b15 commit 4035bdd
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 119 deletions.
8 changes: 5 additions & 3 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"scripts": {
"test": "jest --no-cache",
"test-cov": "jest --no-cache --coverage",
"build-dev": "webpack",
"start": "webpack serve"
"build-dev": "webpack --config webpack.dev.js",
"build": "webpack --config webpack.prod.js",
"start": "webpack serve --config webpack.dev.js"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -36,7 +37,8 @@
"style-loader": "^3.3.3",
"typescript": "^5.3.3",
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
"webpack-cli": "^5.1.4",
"webpack-merge": "^5.10.0"
},
"dependencies": {
"@emotion/styled": "^11.11.0",
Expand Down
50 changes: 50 additions & 0 deletions demo/webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");

module.exports = {
entry: path.resolve(__dirname, "src/index.tsx"),
output: {
path: path.resolve(__dirname, "dist"),
filename: "index.bundle.js",
},
module: {
rules: [
{
test: /\.([jt]sx?)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
"@babel/preset-typescript",
"@babel/preset-react",
],
},
},
},
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
{ test: /\.json$/, type: "json" },
],
},
externals: {
fs: "fs",
},
externalsType: "window",
plugins: [
new HtmlWebpackPlugin({
title: "MemoryViz Demo",
filename: "./index.html",
template: "./src/html/index.html",
}),
],
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx", ".json", ".css"],
alias: {
"memory-viz": path.resolve(__dirname, "../memory-viz/src"),
},
},
};
64 changes: 0 additions & 64 deletions demo/webpack.config.js

This file was deleted.

17 changes: 17 additions & 0 deletions demo/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");

module.exports = merge(common, {
mode: "development",
devtool: "inline-source-map",
devServer: {
static: {
directory: path.join(__dirname, "dist"),
},
compress: true,
port: 9000,
client: {
overlay: false,
},
},
});
7 changes: 7 additions & 0 deletions demo/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");

module.exports = merge(common, {
mode: "production",
devtool: "source-map",
});
2 changes: 1 addition & 1 deletion docs/docs/99-api/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: "index"
title: "MemoryViz"
title: "memory-viz"
sidebar_label: "Readme"
sidebar_position: 0
custom_edit_url: null
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/99-api/modules.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
id: "modules"
title: "MemoryViz"
title: "memory-viz"
sidebar_label: "Exports"
sidebar_position: 0.5
custom_edit_url: null
Expand Down Expand Up @@ -32,4 +32,4 @@ the produced canvas

#### Defined in

user_functions.ts:29
[user_functions.ts:29](https://github.com/david-yz-liu/memory-viz/blob/4d72b15/memory-viz/src/user_functions.ts#L29)
9 changes: 5 additions & 4 deletions memory-viz/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"scripts": {
"test": "jest --no-cache",
"test-cov": "jest --no-cache --coverage",
"watch": "webpack --watch",
"build-dev": "tsc && webpack",
"build": "tsc && webpack --mode production"
"watch": "webpack --watch --config webpack.dev.js",
"build-dev": "tsc && webpack --config webpack.dev.js",
"build": "tsc && webpack --config webpack.prod.js"
},
"keywords": [
"education",
Expand Down Expand Up @@ -40,6 +40,7 @@
"ts-node": "^10.9.2",
"typescript": "^5.3.3",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.1"
"webpack-cli": "^5.0.1",
"webpack-merge": "^5.10.0"
}
}
40 changes: 40 additions & 0 deletions memory-viz/webpack.common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const path = require("path");

module.exports = {
// target: "web",
entry: path.resolve(__dirname, "src/index.ts"),
output: {
path: path.resolve(__dirname, "dist"),
filename: "memory_viz.bundle.js",
library: {
name: "MemoryViz",
type: "umd",
export: "default",
},
globalObject: "this",
clean: true,
},
module: {
rules: [
{
test: /\.([jt]s)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env",
"@babel/preset-typescript",
],
},
},
},
],
},
externals: {
fs: "fs",
},
resolve: {
extensions: [".ts", ".js"],
},
};
43 changes: 0 additions & 43 deletions memory-viz/webpack.config.js

This file was deleted.

10 changes: 10 additions & 0 deletions memory-viz/webpack.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");

module.exports = merge(common, {
mode: "development",
devtool: "inline-source-map",
devServer: {
static: "./dist",
},
});
7 changes: 7 additions & 0 deletions memory-viz/webpack.prod.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const { merge } = require("webpack-merge");
const common = require("./webpack.common.js");

module.exports = merge(common, {
mode: "production",
devtool: "source-map",
});
6 changes: 4 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4035bdd

Please sign in to comment.