Skip to content

Commit

Permalink
move out from devOptions to buildOptions (#1337)
Browse files Browse the repository at this point in the history
* move out to build options

* Update config.ts

* Update config.ts
  • Loading branch information
FredKSchott committed Oct 16, 2020
1 parent c751555 commit 45a746e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 15 deletions.
7 changes: 5 additions & 2 deletions docs/10-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,6 @@ Options:

- **`devOptions.port`** | `number` | Default: `8080`
- The port number to run the dev server on.
- **`devOptions.out`** | `string` | Default: `"build"`
- The local directory that we output your final build to.
- **`devOptions.bundle`** | `boolean`
- Create an optimized, bundled build for production.
- You must have [Parcel](https://parceljs.org/) as a dev dependency in your project.
Expand All @@ -198,6 +196,9 @@ Options:
- When HMR is enabled, toggles whether or not a browser overlay should display javascript errors.
- **`devOptions.secure`** | `boolean`
- Toggles whether or not Snowpack dev server should use HTTPS with HTTP2 enabled.
- **`devOptions.out`** | `string` | Default: `"build"`
- _NOTE:_ Deprecated, see `buildOptions.out`.
- The local directory that we output your final build to.

#### `config.buildOptions`

Expand All @@ -218,6 +219,8 @@ buildOptions: {

Options:

- **`buildOptions.out`** | `string` | Default: `"build"`
- The local directory that we output your final build to.
- **`buildOptions.baseUrl`** | `string` | Default: `/`
- In your HTML, replace all instances of `%PUBLIC_URL%` with this (inspired by the same [Create React App](https://create-react-app.dev/docs/using-the-public-folder/) concept). This is useful if your app will be deployed to a subdirectory. _Note: if you have `homepage` in your `package.json`, Snowpack will actually pick up on that, too._
- **`buildOptions.clean`** | `boolean` | Default: `false`
Expand Down
8 changes: 4 additions & 4 deletions snowpack/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class FileBuilder {
// in the final build, so we mark them to be written to disk at the next step.
if (isProxyImport) {
if (isAbsoluteUrlPath) {
this.filesToProxy.push(path.resolve(this.config.devOptions.out, resolvedImportPath));
this.filesToProxy.push(path.resolve(this.config.buildOptions.out, resolvedImportPath));
} else {
this.filesToProxy.push(path.resolve(path.dirname(outLoc), resolvedImportPath));
}
Expand All @@ -239,7 +239,7 @@ class FileBuilder {
if (isAbsoluteUrlPath) {
resolvedImportUrl = relativeURL(
path.dirname(outLoc),
path.resolve(this.config.devOptions.out, resolvedImportPath),
path.resolve(this.config.buildOptions.out, resolvedImportPath),
);
}
// Make sure that a relative URL always starts with "./"
Expand All @@ -264,7 +264,7 @@ class FileBuilder {
async getProxy(originalFileLoc: string) {
const proxiedCode = this.output[originalFileLoc];
const proxiedUrl = originalFileLoc
.substr(this.config.devOptions.out.length)
.substr(this.config.buildOptions.out.length)
.replace(/\\/g, '/');
return wrapImportProxy({
url: proxiedUrl,
Expand Down Expand Up @@ -293,7 +293,7 @@ export async function command(commandOptions: CommandOptions) {
}
}

const buildDirectoryLoc = config.devOptions.out;
const buildDirectoryLoc = config.buildOptions.out;
const internalFilesBuildLoc = path.join(buildDirectoryLoc, config.buildOptions.metaDir);

if (config.buildOptions.clean) {
Expand Down
15 changes: 11 additions & 4 deletions snowpack/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ const DEFAULT_CONFIG: Partial<SnowpackConfig> = {
hostname: 'localhost',
port: 8080,
open: 'default',
out: 'build',
output: 'dashboard',
fallback: 'index.html',
hmrDelay: 0,
hmrPort: undefined,
hmrErrorOverlay: true,
},
buildOptions: {
out: 'build',
baseUrl: '/',
webModulesUrl: '/web_modules',
clean: false,
Expand Down Expand Up @@ -93,7 +93,6 @@ const configSchema = {
properties: {
secure: {type: 'boolean'},
port: {type: 'number'},
out: {type: 'string'},
fallback: {type: 'string'},
bundle: {type: 'boolean'},
open: {type: 'string'},
Expand All @@ -102,6 +101,8 @@ const configSchema = {
hmrDelay: {type: 'number'},
hmrPort: {type: 'number'},
hmrErrorOverlay: {type: 'boolean'},
// DEPRECATED
out: {type: 'string'},
},
},
installOptions: {
Expand Down Expand Up @@ -143,6 +144,7 @@ const configSchema = {
buildOptions: {
type: ['object'],
properties: {
out: {type: 'string'},
baseUrl: {type: 'string'},
clean: {type: 'boolean'},
metaDir: {type: 'string'},
Expand Down Expand Up @@ -560,11 +562,16 @@ function normalizeAlias(config: SnowpackConfig, cwd: string, createMountAlias: b
function normalizeConfig(config: SnowpackConfig): SnowpackConfig {
const cwd = process.cwd();
config.knownEntrypoints = (config as any).install || [];
config.devOptions.out = path.resolve(cwd, config.devOptions.out);
// @ts-ignore
if (config.devOptions.out) {
logger.debug('`devOptions.out` is now `buildOptions.out`! `devOptions.out` will be deprecated in the next major release.');
};
// @ts-ignore
config.buildOptions.out = path.resolve(cwd, config.buildOptions.out || config.devOptions.out);
config.installOptions.rollup = config.installOptions.rollup || {};
config.installOptions.rollup.plugins = config.installOptions.rollup.plugins || [];
config.exclude = Array.from(
new Set([...ALWAYS_EXCLUDE, `${config.devOptions.out}/**/*`, ...config.exclude]),
new Set([...ALWAYS_EXCLUDE, `${config.buildOptions.out}/**/*`, ...config.exclude]),
);

if (!config.proxy) {
Expand Down
2 changes: 1 addition & 1 deletion snowpack/src/types/snowpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export interface SnowpackConfig {
secure: boolean;
hostname: string;
port: number;
out: string;
fallback: string;
open: string;
output: 'stream' | 'dashboard';
Expand All @@ -146,6 +145,7 @@ export interface SnowpackConfig {
};
installOptions: InstallOptions;
buildOptions: {
out: string;
baseUrl: string;
webModulesUrl: string;
clean: boolean;
Expand Down
4 changes: 2 additions & 2 deletions test/build/config-out/__snapshots__
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ exports[`snowpack build config-out: build/package.json 1`] = `
\\"private\\": true,
\\"version\\": \\"1.0.1\\",
\\"name\\": \\"@snowpack/test-config-out\\",
\\"description\\": \\"Test for devOptions.out\\",
\\"description\\": \\"Test for buildOptions.out\\",
\\"scripts\\": {
\\"testbuild\\": \\"snowpack build\\"
},
\\"snowpack\\": {
\\"devOptions\\": {
\\"buildOptions\\": {
\\"out\\": \\"TEST_BUILD_OUT\\"
},
\\"exclude\\": [
Expand Down
4 changes: 2 additions & 2 deletions test/build/config-out/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
"private": true,
"version": "1.0.1",
"name": "@snowpack/test-config-out",
"description": "Test for devOptions.out",
"description": "Test for buildOptions.out",
"scripts": {
"testbuild": "snowpack build"
},
"snowpack": {
"devOptions": {
"buildOptions": {
"out": "TEST_BUILD_OUT"
},
"exclude": [
Expand Down

1 comment on commit 45a746e

@vercel
Copy link

@vercel vercel bot commented on 45a746e Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.