Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/busy-worms-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'playroom': minor
---

Improve user-side performance and install size by prebundling source
3 changes: 3 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ jobs:
- name: Test
run: pnpm test

- name: Build
run: pnpm package

- name: Cypress
run: |
pnpm cypress:verify
Expand Down
57 changes: 10 additions & 47 deletions lib/makeWebpackConfig.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
const path = require('path');

const FriendlyErrorsWebpackPlugin = require('@soda/friendly-errors-webpack-plugin');
const { cssFileFilter } = require('@vanilla-extract/integration');
const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const webpack = require('webpack');
Expand All @@ -14,7 +12,7 @@ const makeDefaultWebpackConfig = require('./makeDefaultWebpackConfig');
const playroomPath = path.resolve(__dirname, '..');
const includePaths = [
path.resolve(playroomPath, 'lib'),
path.resolve(playroomPath, 'src'),
path.resolve(playroomPath, 'dist'),
path.resolve(playroomPath, 'utils'),
];

Expand All @@ -29,9 +27,9 @@ module.exports = async (playroomConfig, options) => {
const ourConfig = {
mode: options.production ? 'production' : 'development',
entry: {
index: [require.resolve('../src/entries/index.tsx')],
frame: [require.resolve('../src/entries/frame.tsx')],
preview: [require.resolve('../src/entries/preview.tsx')],
index: [require.resolve('../dist/src/index.mjs')],
frame: [require.resolve('../dist/src/frame.mjs')],
preview: [require.resolve('../dist/src/preview.mjs')],
},
output: {
filename: '[name].[contenthash].js',
Expand All @@ -50,22 +48,22 @@ module.exports = async (playroomConfig, options) => {
),
__PLAYROOM_ALIAS__SNIPPETS__: playroomConfig.snippets
? relativeResolve(playroomConfig.snippets)
: require.resolve('./defaultModules/snippets.ts'),
: require.resolve('../dist/src/defaultModules/snippets.mjs'),
__PLAYROOM_ALIAS__THEMES__: playroomConfig.themes
? relativeResolve(playroomConfig.themes)
: require.resolve('./defaultModules/themes.ts'),
: require.resolve('../dist/src/defaultModules/themes.mjs'),
__PLAYROOM_ALIAS__FRAME_COMPONENT__: playroomConfig.frameComponent
? relativeResolve(playroomConfig.frameComponent)
: require.resolve('./defaultModules/FrameComponent.tsx'),
: require.resolve('../dist/src/defaultModules/FrameComponent.mjs'),
__PLAYROOM_ALIAS__USE_SCOPE__: playroomConfig.scope
? relativeResolve(playroomConfig.scope)
: require.resolve('./defaultModules/useScope.ts'),
: require.resolve('../dist/src/defaultModules/useScope.mjs'),
},
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
test: /\.m?js$/,
include: includePaths,
use: [
{
Expand All @@ -76,39 +74,13 @@ module.exports = async (playroomConfig, options) => {
require.resolve('@babel/preset-env'),
{ shippedProposals: true },
],
[
require.resolve('@babel/preset-react'),
{ runtime: 'automatic' },
],
require.resolve('@babel/preset-typescript'),
],
},
},
],
},
{
test: /\.js$/,
include: includePaths,
use: [
{
loader: require.resolve('babel-loader'),
options: {
presets: [
[
require.resolve('@babel/preset-env'),
{ shippedProposals: true },
],
[
require.resolve('@babel/preset-react'),
{ runtime: 'automatic' },
],
],
},
},
],
},
{
test: /(\.vanilla)?\.css$/i,
test: /\.css$/i,
issuer: isPlayroomRepo ? undefined : /node_modules\/playroom/,
use: [
MiniCssExtractPlugin.loader,
Expand Down Expand Up @@ -165,15 +137,6 @@ module.exports = async (playroomConfig, options) => {
publicPath: '../',
template: path.join(__dirname, '../src/entries/template.html'),
}),
new VanillaExtractPlugin({
test: (filePath) => {
// Only apply VanillaExtract plugin to playroom and its dependency's Vanilla Extract modules
return (
cssFileFilter.test(filePath) &&
includePaths.some((includePath) => filePath.startsWith(includePath))
);
},
}),
new MiniCssExtractPlugin({ ignoreOrder: true }),
...(options.production ? [] : [new FriendlyErrorsWebpackPlugin()]),
],
Expand Down
33 changes: 16 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"bin": {
"playroom": "bin/cli.cjs"
},
"main": "./dist/index.js",
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"types": "./dist/index.d.cts",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"require": "./dist/index.cjs",
"import": "./dist/index.mjs"
},
"./package.json": "./package.json"
},
Expand Down Expand Up @@ -50,7 +50,7 @@
"format": "pnpm lint:eslint --fix && prettier --write '**/*.{js,md,ts,tsx}'",
"version": "changeset version",
"release": "pnpm package && changeset publish",
"package": "tsdown",
"package": "tsdown && tsdown --config ./tsdown.src.config.ts",
"test": "jest src lib",
"post-commit-status": "node scripts/postCommitStatus.js",
"deploy-preview": "surge -p ./cypress/projects/themed/dist",
Expand Down Expand Up @@ -80,21 +80,12 @@
"@babel/parser": "^7.23.4",
"@babel/preset-env": "^7.20.2",
"@babel/preset-react": "^7.18.6",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michaeltaranto I'd appreciate if you could take a hard look at the dependencies, if what I moved to devDeps makes sense, and if anything else could potentially be moved. A bit hard for me to judge, as I don't know what has been added and why.

Also the webpack config and loaders, which I trimmed down - maybe something can be simplified further there as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont recall why we have a requirement for @babel/core (unless its a peer dep of something we use).

The @babel/preset-react package is part of the default webpack config we provide for consumers, so we should add that back in.

Can all the @types/* packages be moved to devdeps now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@babel/core is indeed a peerDep requirement for all other babel packages

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hadn't moved @babel/preset-react, so that should be good already.

Types can indeed move to devDeps, will do so.

"@babel/preset-typescript": "^7.18.6",
"@base-ui/react": "^1.1.0",
"@capsizecss/metrics": "^3.5.0",
"@capsizecss/vanilla-extract": "^2.0.4",
"@soda/friendly-errors-webpack-plugin": "^1.8.1",
"@types/codemirror": "^5.60.5",
"@types/prettier": "^2.7.1",
"@types/react": "^18.0.0 || ^19.0.0",
"@types/react-dom": "^18.0.0 || ^19.0.0",
"@vanilla-extract/css": "^1.9.2",
"@vanilla-extract/css-utils": "^0.1.3",
"@vanilla-extract/dynamic": "^2.1.2",
"@vanilla-extract/integration": "^8.0.4",
"@vanilla-extract/sprinkles": "^1.5.1",
"@vanilla-extract/webpack-plugin": "^2.3.6",
"@zumer/snapdom": "^1.9.14",
"babel-loader": "^9.1.0",
"clsx": "^2.1.1",
Expand Down Expand Up @@ -122,20 +113,27 @@
"scope-eval": "^1.0.0",
"sucrase": "^3.35.1",
"tinyglobby": "^0.2.12",
"typescript": ">=5.0.0",
"use-debounce": "^10.0.0",
"webpack": "^5.75.0",
"webpack-dev-server": "^5.0.2",
"webpack-merge": "^5.8.0"
},
"devDependencies": {
"@actions/core": "^1.10.0",
"@babel/preset-typescript": "^7.18.6",
"@capsizecss/metrics": "^3.5.0",
"@capsizecss/vanilla-extract": "^2.0.4",
"@changesets/changelog-github": "^0.5.1",
"@changesets/cli": "^2.28.1",
"@octokit/rest": "^19.0.5",
"@testing-library/cypress": "^10.1.0",
"@types/jest": "^29.2.4",
"@types/node": "^18.11.9",
"@types/node": "^20.19.30",
"@vanilla-extract/css": "^1.9.2",
"@vanilla-extract/css-utils": "^0.1.3",
"@vanilla-extract/dynamic": "^2.1.2",
"@vanilla-extract/rollup-plugin": "^1.5.1",
"@vanilla-extract/sprinkles": "^1.5.1",
"concurrently": "^9.1.2",
"cypress": "^15.5.0",
"eslint": "^9.23.0",
Expand All @@ -148,7 +146,8 @@
"serve": "^14.2.5",
"start-server-and-test": "^2.0.11",
"surge": "^0.24.6",
"tsdown": "^0.12.7"
"tsdown": "^0.20.0",
"typescript": ">=5.0.0"
},
"peerDependencies": {
"react": "^18 || ^19",
Expand Down
Loading