Skip to content

Commit

Permalink
fix: clean up dist folder setup
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Mar 14, 2021
1 parent e9780bb commit 7d16d98
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 15 deletions.
6 changes: 4 additions & 2 deletions core/core/src/node-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ export const findUpFile = (
export const defaultDistFolder = 'dist';

export const getDistName = (options: BuildProps): string => {
const dist =
options.distFolder || path.join(process.cwd(), defaultDistFolder);
const dist = path.join(
process.cwd(),
options.distFolder || defaultDistFolder,
);
return dist;
};

Expand Down
2 changes: 1 addition & 1 deletion examples/react-webpack-5/webpack.dev.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,5 @@ const config: webpack.Configuration & {

export default withComponentControls({
config,
options: { configPath: '.config', distFolder: publicPath },
options: { configPath: '.config', distFolder: publicFolder },
});
3 changes: 1 addition & 2 deletions examples/react-webpack-5/webpack.prod.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const CopyPlugin = require('copy-webpack-plugin');
import { withComponentControls } from '@component-controls/react-router-integration/webpack-build';

const publicFolder = process.env.PUBLIC_PATH || 'public';
const publicPath = path.join(__dirname, publicFolder);
const distFolder = process.env.BUILD_PATH || 'build';
const distPath = path.join(__dirname, distFolder);

Expand Down Expand Up @@ -65,5 +64,5 @@ const config: webpack.Configuration = {

export default withComponentControls({
config,
options: { configPath: '.config', distFolder: publicPath },
options: { configPath: '.config', distFolder: publicFolder },
});
2 changes: 1 addition & 1 deletion examples/react-webpack/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ module.exports = withComponentControls({
config,
options: {
configPath: '.config',
distFolder: publicPath,
distFolder: publicFolder,
},
});
3 changes: 1 addition & 2 deletions examples/react-webpack/webpack.prod.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const {
} = require('@component-controls/react-router-integration/webpack-build');

const publicFolder = process.env.PUBLIC_PATH || 'public';
const publicPath = path.join(__dirname, publicFolder);
const distFolder = process.env.BUILD_PATH || 'build';
const distPath = path.join(__dirname, distFolder);

Expand Down Expand Up @@ -66,5 +65,5 @@ const config = {

module.exports = withComponentControls({
config,
options: { configPath: '.config', distFolder: publicPath },
options: { configPath: '.config', distFolder: publicFolder },
});
4 changes: 2 additions & 2 deletions examples/stories/src/tutorial/getting-started/ssg/webpack.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const config = {
// the following will compile your documentation files before launching the webpack proces to compile the documentation site itself:
module.exports = withComponentControls({
config,
options: { configPath: '.config', distFolder: publicPath },
options: { configPath: '.config', distFolder: publicFolder },
});
```

Expand All @@ -86,7 +86,7 @@ module.exports = withComponentControls({
config,
options: {
configPath: '.config',
distFolder: publicPath,
distFolder: publicFolder,
},
});
```
Expand Down
8 changes: 5 additions & 3 deletions integrations/base-integration/src/webpack-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ const createOptions = (buildOptions?: BuildProps): BuildProps => {
return acc;
}, {});

const distFolder =
options.distFolder || path.join(process.cwd(), defaultDistFolder);
const distFolder = options.distFolder || defaultDistFolder;
const staticFolder = path.join(options.distFolder || distFolder, 'static');
return mergeConfig<BuildProps>(
mergeConfig(defaultCompileProps, {
Expand Down Expand Up @@ -100,7 +99,10 @@ export const webpackConfig = ({
options?: BuildProps;
}): any => {
const buildOptions = createOptions(options);
const bundleFilePath = getBundleName(buildOptions);
const bundleFilePath = path.resolve(
process.cwd(),
getBundleName(buildOptions),
);
return {
...config,
resolve: {
Expand Down
12 changes: 10 additions & 2 deletions integrations/nextjs-plugin/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import fs from 'fs';
import path from 'path';
import { BuildProps, RuleOptions } from '@component-controls/core';
import { getCSSBundleName } from '@component-controls/core/node-utils';
import {
getCSSBundleName,
defaultDistFolder,
} from '@component-controls/core/node-utils';
import {
buildBundle,
webpackConfig,
Expand All @@ -11,7 +15,7 @@ module.exports = ({
configPath,
presets,
staticFolder,
distFolder,
distFolder = defaultDistFolder,
webpack,
...rest
}: BuildProps) => () => {
Expand All @@ -26,6 +30,7 @@ module.exports = ({
return {
/**
* we need some async function, to make sure the compilation process is completed
* headers is the first called from async redirects() amd async rewrites()
*/
async headers() {
await buildBundle({
Expand All @@ -44,6 +49,9 @@ module.exports = ({
const loader: any = config.module?.rules?.find(
(r: any) => (r?.use as any)?.loader === 'next-babel-loader',
);
if (loader) {
loader.exclude = [path.join(process.cwd(), distFolder)];
}
if (loader?.options) {
(loader.options as any).babelPresetPlugins.push(
'@emotion/babel-plugin',
Expand Down

0 comments on commit 7d16d98

Please sign in to comment.