Skip to content

Commit

Permalink
feat: Add support for building using a baseUrl (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
BrunnerLivio committed Mar 11, 2020
1 parent b75bc63 commit bd2abbc
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ module.exports = {
Hello World!
</Button>
`,
baseUrl: '/playroom/',
webpackConfig: () => ({
// Custom webpack config goes here...
})
Expand Down
5 changes: 3 additions & 2 deletions lib/makeWebpackConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module.exports = async (playroomConfig, options) => {
output: {
filename: '[name].[hash].js',
path: path.resolve(playroomConfig.cwd, playroomConfig.outputPath),
publicPath: ''
publicPath: playroomConfig.baseUrl
},
resolve: {
extensions: ['.tsx', '.ts', '.jsx', '.js', '.json'],
Expand Down Expand Up @@ -144,7 +144,8 @@ module.exports = async (playroomConfig, options) => {
: 'Playroom',
chunksSortMode: 'none',
chunks: ['index'],
filename: 'index.html'
filename: 'index.html',
base: playroomConfig.baseUrl
}),
new HtmlWebpackPlugin({
title: 'Playroom Frame',
Expand Down
1 change: 1 addition & 0 deletions lib/provideDefaultConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ module.exports = ({ storageKey, ...restConfig }) => ({
port: 9000,
openBrowser: true,
storageKey: storageKey || generateStorageKey(),
baseUrl: '',
...restConfig
});
5 changes: 4 additions & 1 deletion lib/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const open = require('open');
const makeWebpackConfig = require('./makeWebpackConfig');

module.exports = async (config, callback) => {
const webpackConfig = await makeWebpackConfig(config, { production: false });
const webpackConfig = await makeWebpackConfig(
{ ...config, baseUrl: '' },
{ production: false }
);
const webpackDevServerConfig = {
hot: true,
stats: {},
Expand Down
6 changes: 5 additions & 1 deletion src/Playroom/Preview/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface PreviewProps {
widths: PlayroomProps['widths'];
}

const playroomConfig = (window.__playroomConfig__ = __PLAYROOM_GLOBAL__CONFIG__);

export default function Preview({ code, themes, widths }: PreviewProps) {
const scrollingPanelRef = useRef<HTMLDivElement | null>(null);

Expand Down Expand Up @@ -51,7 +53,9 @@ export default function Preview({ code, themes, widths }: PreviewProps) {
</div>
<Iframe
intersectionRootRef={scrollingPanelRef}
src={`frame.html#?themeName=${encodeURIComponent(
src={`${
playroomConfig.baseUrl
}frame.html#?themeName=${encodeURIComponent(
frame.theme
)}&code=${encodeURIComponent(renderCode)}`}
className={styles.frame}
Expand Down
1 change: 1 addition & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface PlayroomConfig {
cwd?: string;
storageKey?: string;
webpackConfig?: () => void;
baseUrl?: string;
}

interface InternalPlayroomConfig extends PlayroomConfig {
Expand Down

0 comments on commit bd2abbc

Please sign in to comment.