-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(docz): use webpack 4 instead of parcel
- Loading branch information
1 parent
d07667b
commit 1e5742c
Showing
32 changed files
with
2,598 additions
and
1,987 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,4 +28,5 @@ es | |
lib | ||
stats.html | ||
build | ||
dist | ||
index.d.ts |
2 changes: 1 addition & 1 deletion
2
packages/playgrood/bin/index.js → packages/playgrodd/bin/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
import findup from 'find-up' | ||
import webpack, { Loader, Configuration } from 'webpack' | ||
import HtmlWebpackPlugin from 'html-webpack-plugin' | ||
|
||
import { IComponentMap } from '../utils/components' | ||
import * as paths from './paths' | ||
|
||
export { config as devServerConfig } from './dev-server' | ||
|
||
const babelLoader = (babelrc: string | null): Loader => ({ | ||
loader: require.resolve('babel-loader'), | ||
options: babelrc | ||
? JSON.parse(babelrc) | ||
: { | ||
babelrc: false, | ||
cacheDirectory: true, | ||
presets: [ | ||
require.resolve('@babel/preset-env'), | ||
require.resolve('@babel/preset-react'), | ||
], | ||
}, | ||
}) | ||
|
||
export const config = async ( | ||
components: IComponentMap | ||
): Promise<Configuration> => { | ||
const babelrcPath = await findup('.babelrc') | ||
const babelrc = babelrcPath ? fs.readFileSync(babelrcPath, 'utf-8') : null | ||
|
||
return { | ||
mode: 'development', | ||
context: paths.ROOT, | ||
entry: [ | ||
...Object.values(components).map(({ filepath: f }) => f), | ||
paths.INDEX_JS, | ||
], | ||
output: { | ||
pathinfo: true, | ||
path: paths.DIST, | ||
publicPath: '/', | ||
filename: 'static/js/[name].js', | ||
sourceMapFilename: 'static/js/[name].js.map', | ||
crossOriginLoading: 'anonymous', | ||
devtoolModuleFilenameTemplate: (info: any) => | ||
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'), | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(js|jsx)$/, | ||
exclude: /node_modules/, | ||
include: [paths.ROOT], | ||
use: babelLoader(babelrc), | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'], | ||
}, | ||
plugins: [ | ||
new webpack.DefinePlugin({ | ||
__PLAYGRODD_COMPONENTS__: JSON.stringify(components), | ||
}), | ||
new HtmlWebpackPlugin({ | ||
template: paths.INDEX_HTML, | ||
}), | ||
], | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import * as paths from './paths' | ||
|
||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http' | ||
const host = process.env.HOST || '0.0.0.0' | ||
|
||
export const config = (compiler: any) => ({ | ||
compress: true, | ||
clientLogLevel: 'none', | ||
contentBase: paths.DIST, | ||
watchContentBase: true, | ||
publicPath: '/', | ||
hot: true, | ||
quiet: true, | ||
noInfo: true, | ||
https: protocol === 'https', | ||
host: host, | ||
overlay: false, | ||
watchOptions: { | ||
ignored: /node_modules/, | ||
}, | ||
stats: { | ||
colors: true, | ||
chunks: false, | ||
chunkModules: false, | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as React from 'react' | ||
import { renderToString } from 'react-dom/server' | ||
|
||
const Html = () => ( | ||
<html> | ||
<head> | ||
<title>Playgrodd</title> | ||
<body> | ||
<div id="root" /> | ||
</body> | ||
</head> | ||
</html> | ||
) | ||
|
||
export const generateHtml = () => renderToString(<Html />) | ||
|
||
export const generateJs = () => | ||
`import 'babel-polyfill' | ||
import * as React from 'react' | ||
import { render } from 'react-dom' | ||
import { App } from 'playgrodd-theme-default' | ||
render( | ||
<App />, | ||
document.querySelector('#root') | ||
)` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import fs from 'fs' | ||
import mkdir from 'mkdirp' | ||
import trash from 'trash' | ||
import webpack from 'webpack' | ||
|
||
import * as paths from './paths' | ||
import { config } from './config' | ||
import { IComponentMap } from '../utils/components' | ||
import { generateHtml, generateJs } from './generate-files' | ||
|
||
export { config as devServerConfig } from './dev-server' | ||
|
||
const checkMkdirTheme = (): void => { | ||
try { | ||
fs.lstatSync(paths.THEME) | ||
} catch (err) { | ||
mkdir.sync(paths.THEME) | ||
} | ||
} | ||
|
||
const tempFile = (filepath: string, content: string) => { | ||
checkMkdirTheme() | ||
fs.writeFileSync(filepath, content, 'utf-8') | ||
} | ||
|
||
export const createCompiler = async (components: IComponentMap) => { | ||
const js = generateJs() | ||
const html = generateHtml() | ||
const webpackConfig = await config(components) | ||
|
||
await trash(paths.THEME) | ||
tempFile(paths.INDEX_JS, js) | ||
tempFile(paths.INDEX_HTML, html) | ||
|
||
return webpack(webpackConfig) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import * as fs from 'fs' | ||
import * as path from 'path' | ||
|
||
export const ROOT = fs.realpathSync(process.cwd()) | ||
export const PLAYGRODD = path.join(ROOT, '.playgrodd') | ||
export const THEME = path.join(PLAYGRODD, 'theme') | ||
export const INDEX_JS = path.join(THEME, 'index.jsx') | ||
export const INDEX_HTML = path.join(THEME, 'index.html') | ||
|
||
export const DIST = path.join(PLAYGRODD, 'dist') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import * as React from 'react' | ||
|
||
export const Html = () => ( | ||
<html> | ||
<head> | ||
<title>Playgrodd</title> | ||
<body> | ||
<div id="root" /> | ||
</body> | ||
</head> | ||
</html> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as React from 'react' | ||
import { Router } from 'react-router-dom' | ||
import { createBrowserHistory, History } from 'history' | ||
import { Provider } from 'unstated' | ||
|
||
import { container } from '../documents/container' | ||
|
||
export const history: History = createBrowserHistory() | ||
|
||
export const Playgrodd: React.SFC = ({ children }) => ( | ||
<Router history={history}> | ||
<Provider inject={[container]}>{children}</Provider> | ||
</Router> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import * as React from 'react' | ||
import { Subscribe } from 'unstated' | ||
import { Route } from 'react-router-dom' | ||
|
||
import { Doc } from '../documents' | ||
import { IComponent } from '../utils/components' | ||
import { DocumentsContainer } from '../documents/container' | ||
|
||
const components = __PLAYGRODD_COMPONENTS__ | ||
const loadDocument = (doc: Doc) => { | ||
const { route }: IComponent = components[doc.getName()] | ||
const sections = doc.getSections() | ||
|
||
return ( | ||
<Route | ||
exact | ||
key={route} | ||
path={route} | ||
render={() => | ||
sections.map(({ id, title, render: Component }) => ( | ||
<React.Fragment key={id}> | ||
{title && <h2>{title}</h2>} | ||
<Component /> | ||
</React.Fragment> | ||
)) | ||
} | ||
/> | ||
) | ||
} | ||
|
||
export const Preview: React.SFC = () => ( | ||
<Subscribe to={[DocumentsContainer]}> | ||
{({ state }) => state.documents.map(loadDocument)} | ||
</Subscribe> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Container } from 'unstated' | ||
|
||
import { Doc } from './' | ||
|
||
export interface DocumentState { | ||
documents: Doc[] | ||
} | ||
|
||
export class DocumentsContainer extends Container<DocumentState> { | ||
state = { | ||
documents: [], | ||
} | ||
|
||
public add(document: Doc) { | ||
this.setState({ | ||
documents: [document, ...this.state.documents], | ||
}) | ||
} | ||
} | ||
|
||
export const container = new DocumentsContainer() |
Oops, something went wrong.