Skip to content

Commit

Permalink
cleanup kitchensink webpack
Browse files Browse the repository at this point in the history
  • Loading branch information
damassi committed Nov 2, 2023
1 parent bca98b6 commit 768753b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 58 deletions.
2 changes: 1 addition & 1 deletion examples/kitchen-sink/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"main": "index.js",
"license": "MIT",
"scripts": {
"start": "babel-node --extensions '.ts,.tsx,.js,.jsx' src/server.tsx"
"start": "babel-node --extensions '.ts,.tsx,.js,.jsx' server.tsx"
},
"dependencies": {
"@artsy/detect-responsive-traits": "0.1.0",
Expand Down
37 changes: 17 additions & 20 deletions examples/kitchen-sink/server.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import Webpack from "webpack"
import WebpackDevServer from "webpack-dev-server"
// @ts-ignore
import webpackConfig from "./webpack.config"
import express from "express"
import ReactDOMServer from "react-dom/server"
import React from "react"
import chalk from "chalk"

import webpack from "webpack"
import webpackDevMiddleware from "webpack-dev-middleware"
import webpackConfig from "./webpack.config"

import { findDevice } from "@artsy/detect-responsive-traits"

import {
Expand All @@ -19,8 +19,17 @@ import {
} from "./src/Media"
import { App } from "./src/App"

const compiler = webpack(webpackConfig)
const app = express()

app.use(
webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
serverSideRender: true,
stats: "errors-only",
})
)

/**
* Find the breakpoints and interactions that the server should render
*/
Expand Down Expand Up @@ -95,7 +104,7 @@ app.get("/rehydration", (req, res) => {
// loading the JS bundle.
setTimeout(function () {
var script = document.createElement("script")
script.src = "/bundle.js"
script.src = "/assets/app.js"
document.getElementsByTagName("head")[0].appendChild(script);
document.getElementById("loading-indicator").remove();
}, 1000)
Expand All @@ -117,7 +126,7 @@ app.get("/client-only", (_req, res) => {
<script>
setTimeout(function () {
var script = document.createElement("script")
script.src = "/bundle.js"
script.src = "/assets/app.js"
document.getElementsByTagName("head")[0].appendChild(script);
}, 1000)
</script>
Expand Down Expand Up @@ -177,18 +186,6 @@ function log(userAgent: string, onlyMatch?: string[], device?: string) {
)
}

const compiler = Webpack(webpackConfig)
const devServerOptions = Object.assign({}, webpackConfig.devServer, {
stats: {
colors: true,
},
before(s) {
s.use(app)
},
})
const server = new WebpackDevServer(compiler, devServerOptions)

server.listen(8080, "127.0.0.1", () => {
// tslint:disable-next-line:no-console
console.log("Starting server on http://localhost:8080")
app.listen(3000, () => {
console.warn("\nApp started at http://localhost:3000 \n")
})
29 changes: 29 additions & 0 deletions examples/kitchen-sink/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const webpack = require("webpack")

module.exports = {
mode: "development",
devtool: "eval",
entry: {
app: "./src/client.tsx",
},
output: {
filename: "[name].js",
publicPath: "/assets",
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
include: /src/,
use: {
loader: "babel-loader",
},
},
],
},
plugins: [new webpack.HotModuleReplacementPlugin()],
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx"],
modules: ["node_modules", "src"],
},
}
36 changes: 0 additions & 36 deletions examples/kitchen-sink/webpack.config.ts

This file was deleted.

5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"rootDir": "src",
"skipLibCheck": true,
"target": "es2015",
"strict": true
"strict": true,

"keyofStringsOnly": true,
"ignoreDeprecations": "5.0"
},
"exclude": ["node_modules/*", "dist", "examples/*", "src/**/__test__/*"]
}

0 comments on commit 768753b

Please sign in to comment.