1
0
Fork 0

chore(fs.dev): Webpack aliases to load local code from source

These changes force webpack to load the local pacakges (like
patterns and so on) from source, rather than from a compiled bundle.
This means that the lab site will reload whenever one makes changes
to pattern code.
This commit is contained in:
Joost De Cock 2022-01-24 12:34:29 +01:00
parent 2169994f0a
commit 2ea353a475
7 changed files with 35 additions and 10 deletions

View file

@ -1,5 +1,4 @@
import React from 'react' import React from 'react'
import config from 'site/freesewing.config.js'
import DesignIcon from 'shared/components/icons/design.js' import DesignIcon from 'shared/components/icons/design.js'
import Link from 'next/link' import Link from 'next/link'
@ -16,15 +15,15 @@ const PatternPicker = ({ app }) => {
<span>Patterns</span> <span>Patterns</span>
</div> </div>
<ul tabIndex="0" className="p-2 shadow menu dropdown-content bg-base-100 rounded-box w-52 max-h-96 overflow-y-scroll"> <ul tabIndex="0" className="p-2 shadow menu dropdown-content bg-base-100 rounded-box w-52 max-h-96 overflow-y-scroll">
{Object.keys(config.patterns).map(section => ( {Object.keys(app.patterns).map(section => (
<React.Fragment key={section}> <React.Fragment key={section}>
<li className={` <li className={`
capitalize font-bold text-base-content text-center capitalize font-bold text-base-content text-center
opacity-50 border-b2 my-2 border-base-content opacity-50 border-b2 my-2 border-base-content
`}> `}>
{t(config.navigation[section].__title)} {t(app.navigation[section].__title)}
</li> </li>
{config.patterns[section].map(pattern => ( {app.patterns[section].map(pattern => (
<li key={pattern}> <li key={pattern}>
<Link href={`/${section}/${pattern}`}> <Link href={`/${section}/${pattern}`}>
<button className="btn btn-sm btn-ghost text-base-content"> <button className="btn btn-sm btn-ghost text-base-content">

View file

@ -69,6 +69,7 @@ function useApp(full = true) {
return { return {
// Static vars // Static vars
site: 'lab', site: 'lab',
patterns: config.patterns,
// State // State
language, language,

View file

@ -1,3 +1,11 @@
import configBuilder from '../freesewing.shared/config/next.mjs' import configBuilder from '../freesewing.shared/config/next.mjs'
import config from './freesewing.config.mjs'
export default configBuilder('lab') const allPatterns = []
for (const section in config.patterns) {
for (const pattern of config.patterns[section]) {
allPatterns.push(pattern)
}
}
export default configBuilder('lab', [], allPatterns)

View file

@ -13,7 +13,7 @@ const links = (section, list) => list.map(design => (
</li> </li>
)) ))
const ListPage = ({ sections=Object.keys(config.patterns) }) => { const PatternListPageTemplate = ({ sections=Object.keys(config.patterns) }) => {
const app = useApp() const app = useApp()
return ( return (
<Page app={app} title="FreeSewing Lab" noSearch> <Page app={app} title="FreeSewing Lab" noSearch>
@ -33,7 +33,7 @@ const ListPage = ({ sections=Object.keys(config.patterns) }) => {
<div className="max-w-screen-md"> <div className="max-w-screen-md">
{Object.keys(config.navigation).map(section => { {Object.keys(config.navigation).map(section => {
if (sections.indexOf(section) !== -1) return ( if (sections.indexOf(section) !== -1) return (
<div> <div key={section}>
<h2>{config.navigation[section].__title}</h2> <h2>{config.navigation[section].__title}</h2>
<ul className="flex flex-row flex-wrap gap-2"> <ul className="flex flex-row flex-wrap gap-2">
{links(section, config.patterns[section])} {links(section, config.patterns[section])}
@ -48,4 +48,4 @@ const ListPage = ({ sections=Object.keys(config.patterns) }) => {
) )
} }
export default ListPage export default PatternListPageTemplate

View file

@ -0,0 +1,4 @@
import pattern from 'pkgs/brian/src/index.js'
import PageTemplate from 'site/page-templates/workbench.js'
export default () => <PageTemplate pattern={pattern} />

View file

@ -38,7 +38,6 @@ const WorkbenchWrapper = ({ app, pattern }) => {
// State for display mode and gist // State for display mode and gist
const [mode, setMode] = useState(null) const [mode, setMode] = useState(null)
const [gist, setGist] = useState(defaultGist(pattern, app.language)) const [gist, setGist] = useState(defaultGist(pattern, app.language))
const [fuck, setFuck] = useState('')
// If we don't have the requiremed measurements, // If we don't have the requiremed measurements,
// force mode to measurements // force mode to measurements

View file

@ -1,7 +1,17 @@
import path from 'path' import path from 'path'
import remarkGfm from 'remark-gfm' import remarkGfm from 'remark-gfm'
import { patterns } from '../../../config/packages.mjs'
const config = (site, remarkPlugins=[]) => ({ /*
* This mehthod will return the NextJS configuration
* Parameters:
*
* site: one of 'dev', 'org', or 'lab'
* remarkPlugins: Array of remark plugins to load
* srcPkgs: Array of folders in the monorepo/packages that should be aliased
* so they are loaded from source, rather than from a compiled bundle
*/
const config = (site, remarkPlugins=[], srcPkgs=[]) => ({
experimental: { experimental: {
externalDir: true, externalDir: true,
esmExternals: true, esmExternals: true,
@ -48,6 +58,10 @@ const config = (site, remarkPlugins=[]) => ({
config.resolve.alias.site = path.resolve(`../freesewing.${site}/`) config.resolve.alias.site = path.resolve(`../freesewing.${site}/`)
config.resolve.alias.markdown = path.resolve(`../../markdown/${site}/`) config.resolve.alias.markdown = path.resolve(`../../markdown/${site}/`)
config.resolve.alias.pkgs = path.resolve(`../`) config.resolve.alias.pkgs = path.resolve(`../`)
// This forces webpack to load the code from source, rather than compiled bundle
for (const pkg of srcPkgs) {
config.resolve.alias[`@freesewing/${pkg}$`] = path.resolve(`../${pkg}/src/index.js`)
}
return config return config
} }