Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
65 changes: 14 additions & 51 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/app/index.mjs')],
frame: [require.resolve('../dist/app/frame.mjs')],
preview: [require.resolve('../dist/app/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/app/defaultModules/snippets.mjs'),
__PLAYROOM_ALIAS__THEMES__: playroomConfig.themes
? relativeResolve(playroomConfig.themes)
: require.resolve('./defaultModules/themes.ts'),
: require.resolve('../dist/app/defaultModules/themes.mjs'),
__PLAYROOM_ALIAS__FRAME_COMPONENT__: playroomConfig.frameComponent
? relativeResolve(playroomConfig.frameComponent)
: require.resolve('./defaultModules/FrameComponent.tsx'),
: require.resolve('../dist/app/defaultModules/FrameComponent.mjs'),
__PLAYROOM_ALIAS__USE_SCOPE__: playroomConfig.scope
? relativeResolve(playroomConfig.scope)
: require.resolve('./defaultModules/useScope.ts'),
: require.resolve('../dist/app/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 @@ -146,9 +118,9 @@ module.exports = async (playroomConfig, options) => {
chunksSortMode: 'none',
chunks: ['index'],
filename: 'index.html',
favicon: path.join(__dirname, '../images/favicon.png'),
favicon: path.join(__dirname, '../dist/images/favicon.png'),
base: playroomConfig.baseUrl,
template: path.join(__dirname, '../src/entries/template.html'),
template: path.join(__dirname, '../dist/app/template.html'),
}),
new HtmlWebpackPlugin({
title: 'Playroom Frame',
Expand All @@ -161,18 +133,9 @@ module.exports = async (playroomConfig, options) => {
chunksSortMode: 'none',
chunks: ['preview'],
filename: 'preview/index.html',
favicon: path.join(__dirname, '../images/favicon.png'),
favicon: path.join(__dirname, '../dist/images/favicon.png'),
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))
);
},
template: path.join(__dirname, '../dist/app/template.html'),
}),
new MiniCssExtractPlugin({ ignoreOrder: true }),
...(options.production ? [] : [new FriendlyErrorsWebpackPlugin()]),
Expand Down
43 changes: 19 additions & 24 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,19 @@
"bin": {
"playroom": "bin/cli.cjs"
},
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.ts",
"main": "./dist/utils/index.cjs",
"module": "./dist/utils/index.mjs",
"types": "./dist/utils/index.d.cts",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js"
"require": "./dist/utils/index.cjs",
"import": "./dist/utils/index.mjs"
},
"./package.json": "./package.json"
},
"files": [
"CHANGELOG.md",
".babelrc",
"images",
"lib",
"src",
"utils",
"dist"
],
"scripts": {
Expand Down Expand Up @@ -80,21 +76,8 @@
"@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 @@ -130,12 +113,24 @@
},
"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/codemirror": "^5.60.5",
"@types/jest": "^29.2.4",
"@types/node": "^18.11.9",
"@types/node": "^20.19.30",
"@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/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 +143,7 @@
"serve": "^14.2.5",
"start-server-and-test": "^2.0.11",
"surge": "^0.24.6",
"tsdown": "^0.12.7"
"tsdown": "^0.20.0"
},
"peerDependencies": {
"react": "^18 || ^19",
Expand Down
Loading