Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give the possibility to add a --output website for build and develop … #4745

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/building-with-components.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ import favicon from "./favicon.png";
let inlinedStyles = "";
if (process.env.NODE_ENV === "production") {
try {
inlinedStyles = require("!raw-loader!../public/styles.css");
inlinedStyles = require(`!raw-loader!../${process.env.GATSBY_OUTPUT_DIR}/styles.css`);
} catch (e) {
console.log(e);
}
Expand Down
1 change: 1 addition & 0 deletions docs/docs/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,4 @@ Reserved environment variables:

* `NODE_ENV`
* `PUBLIC_DIR`
* `GATSBY_OUTPUT_DIR`
2 changes: 1 addition & 1 deletion examples/client-only-paths/src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import typography from "./utils/typography"
let stylesStr
if (process.env.NODE_ENV === `production`) {
try {
stylesStr = require(`!raw-loader!../public/styles.css`)
stylesStr = require(`!raw-loader!../${process.env.GATSBY_OUTPUT_DIR}/styles.css`)
} catch (e) {
console.log(e)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/using-postcss-sass/src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const typography = new Typography()
let stylesStr
if (process.env.NODE_ENV === `production`) {
try {
stylesStr = require(`!raw-loader!../public/styles.css`)
stylesStr = require(`!raw-loader!../${process.env.GATSBY_OUTPUT_DIR}/styles.css`)
} catch (e) {
console.log(e)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/using-remark/src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import typography from "./utils/typography"
let stylesStr
if (process.env.NODE_ENV === `production`) {
try {
stylesStr = require(`!raw-loader!../public/styles.css`)
stylesStr = require(`!raw-loader!../${process.env.GATSBY_OUTPUT_DIR}/styles.css`)
} catch (e) {
console.log(e)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/using-sass/src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const typography = new Typography()
let stylesStr
if (process.env.NODE_ENV === `production`) {
try {
stylesStr = require(`!raw-loader!../public/styles.css`)
stylesStr = require(`!raw-loader!../${process.env.GATSBY_OUTPUT_DIR}/styles.css`)
} catch (e) {
console.log(e)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/using-styled-components/src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import typography from "./utils/typography"
let stylesStr
if (process.env.NODE_ENV === `production`) {
try {
stylesStr = require(`!raw-loader!../public/styles.css`)
stylesStr = require(`!raw-loader!../${process.env.GATSBY_OUTPUT_DIR}/styles.css`)
} catch (e) {
console.log(e)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/using-styletron/src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import typography from "./utils/typography"
let stylesStr
if (process.env.NODE_ENV === `production`) {
try {
stylesStr = require(`!raw-loader!../public/styles.css`)
stylesStr = require(`!raw-loader!../${process.env.GATSBY_OUTPUT_DIR}/styles.css`)
} catch (e) {
console.log(e)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/using-stylus/src/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const typography = new Typography()
let stylesStr
if (process.env.NODE_ENV === `production`) {
try {
stylesStr = require(`!raw-loader!../public/styles.css`)
stylesStr = require(`!raw-loader!../${process.env.GATSBY_OUTPUT_DIR}/styles.css`)
} catch (e) {
console.log(e)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/using-typescript/src/html.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as React from "react";
let styles: string;
if (process.env.NODE_ENV === `production`) {
try {
styles = require("!raw-loader!../public/styles.css");
styles = require("!raw-loader!../${process.env.GATSBY_OUTPUT_DIR}/styles.css");
} catch (err) {
console.log(err);
}
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/build-site.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const Main = async () => {
updateBuild(buildId, "FAILURE")
process.exit(code)
}
const publicDir = `${pathToSite}/public`
const publicDir = `${pathToSite}/${process.env.GATSBY_OUTPUT_DIR}`
console.log(`uploading files from ${publicDir}`)

// 1. Push built files to s3 bucket
Expand Down
12 changes: 12 additions & 0 deletions packages/gatsby-cli/src/create-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,16 @@ function buildLocalCommands(cli, isLocalSite) {
alias: `https`,
type: `boolean`,
describe: `Use HTTPS. See https://www.gatsbyjs.org/docs/local-https/ for an initial setup guide`,
})
.option(`output`, {
type: `string`,
default: `public`,
describe: `Set output directory. Defaults to public`,
}),
handler: handlerP(
getCommandHandler(`develop`, (args, cmd) => {
process.env.NODE_ENV = process.env.NODE_ENV || `development`
process.env.GATSBY_OUTPUT_DIR = args.output || `public`
cmd(args)
// Return an empty promise to prevent handlerP from exiting early.
// The development server shouldn't ever exit until the user directly
Expand All @@ -124,10 +130,16 @@ function buildLocalCommands(cli, isLocalSite) {
type: `boolean`,
default: false,
describe: `Build site with link paths prefixed (set prefix in your config).`,
})
.option(`output`, {
type: `string`,
default: `public`,
describe: `Set output directory. Defaults to public`,
}),
handler: handlerP(
getCommandHandler(`build`, (args, cmd) => {
process.env.NODE_ENV = `production`
process.env.GATSBY_OUTPUT_DIR = args.output || `public`
return cmd(args)
})
),
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-feed/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import RSS from "rss"
import merge from "lodash.merge"
import { defaultOptions, runQuery, writeFile } from "./internals"

const publicPath = `./public`
const publicPath = `./${process.env.GATSBY_OUTPUT_DIR}`

// A default function to transform query data into feed entries.
const serialize = ({ query: { site, allMarkdownRemark } }) =>
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-manifest/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ exports.onPostBuild = (args, pluginOptions) =>
new Promise(resolve => {
const manifest = { ...pluginOptions }
delete manifest.plugins
fs.writeFileSync(`./public/manifest.json`, JSON.stringify(manifest))
fs.writeFileSync(`./${process.env.GATSBY_OUTPUT_DIR}/manifest.json`, JSON.stringify(manifest))
resolve()
})
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-netlify/src/plugin-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function applyLayouts(pages, layouts) {
// hashed filenames and ensure we pull in the componentChunkName and layoutComponentChunkName.
export default function makePluginData(store, assetsManifest, pathPrefix) {
const { program, layouts, pages: storePages } = store.getState()
const publicFolder = buildPrefixer(program.directory, `public`)
const publicFolder = buildPrefixer(program.directory, process.env.GATSBY_OUTPUT_DIR)
const stats = require(publicFolder(`stats.json`))
const chunkManifest = normalizeStats(stats)
const pages = applyLayouts(storePages, layouts)
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby-plugin-offline/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports.createPages = ({ boundActionCreators }) => {
}

exports.onPostBuild = (args, pluginOptions) => {
const rootDir = `public`
const rootDir = process.env.GATSBY_OUTPUT_DIR

const options = {
staticFileGlobs: [
Expand All @@ -27,7 +27,7 @@ exports.onPostBuild = (args, pluginOptions) => {
],
stripPrefix: rootDir,
// If `pathPrefix` is configured by user, we should replace
// the `public` prefix with `pathPrefix`.
// the output directory (default: `public`) prefix with `pathPrefix`.
// See more at:
// https:/GoogleChrome/sw-precache#replaceprefix-string
replacePrefix: args.pathPrefix || ``,
Expand Down Expand Up @@ -56,5 +56,5 @@ exports.onPostBuild = (args, pluginOptions) => {

const combinedOptions = _.defaults(pluginOptions, options)

return precache.write(`public/sw.js`, combinedOptions)
return precache.write(`${process.env.GATSBY_OUTPUT_DIR}/sw.js`, combinedOptions)
}
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sharp/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ function queueImageResizing({ file, args = {}, reporter }) {
const imgSrc = `/${file.name}-${
file.internal.contentDigest
}-${argsDigestShort}.${fileExtension}`
const filePath = path.join(process.cwd(), `public`, `static`, imgSrc)
const filePath = path.join(process.cwd(), process.env.GATSBY_OUTPUT_DIR, `static`, imgSrc)

// Create function to call when the image is finished.
let outsideResolve, outsideReject
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-plugin-sitemap/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "path"
import sitemap from "sitemap"
import { defaultOptions, runQuery, writeFile } from "./internals"

const publicPath = `./public`
const publicPath = `./${process.env.GATSBY_OUTPUT_DIR}`

exports.onPostBuild = async ({ graphql }, pluginOptions) => {
const options = { ...pluginOptions }
Expand Down
8 changes: 1 addition & 7 deletions packages/gatsby-remark-autolink-headers/src/gatsby-ssr.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,7 @@ exports.onRenderBody = ({ setHeadComponents }, pluginOptions) => {
h3:hover .anchor svg,
h4:hover .anchor svg,
h5:hover .anchor svg,
h6:hover .anchor svg,
h1 .anchor:focus svg,
h2 .anchor:focus svg,
h3 .anchor:focus svg,
h4 .anchor:focus svg,
h5 .anchor:focus svg,
h6 .anchor:focus svg {
h6:hover .anchor svg {
visibility: visible;
}
`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ describe(`gatsby-remark-copy-linked-files`, () => {
describe(`options.destinationDir`, () => {
const imagePath = `images/sample-image.gif`

it(`throws an error if the destination directory is not within 'public'`, async () => {
it(`throws an error if the destination directory is not within '${process.env.GATSBY_OUTPUT_DIR}'`, async () => {
const markdownAST = remark.parse(`![some absolute image](${imagePath})`)
const invalidDestinationDir = `../destination`
expect.assertions(2)
Expand All @@ -192,7 +192,7 @@ describe(`gatsby-remark-copy-linked-files`, () => {
const validDestinationDir = `path/to/dir`
const expectedNewPath = path.posix.join(
process.cwd(),
`public`,
process.env.GATSBY_OUTPUT_DIR,
validDestinationDir,
`/undefined-undefined.gif`
)
Expand All @@ -215,7 +215,7 @@ describe(`gatsby-remark-copy-linked-files`, () => {
const markdownAST = remark.parse(`![some absolute image](${imagePath})`)
const expectedNewPath = path.posix.join(
process.cwd(),
`public`,
process.env.GATSBY_OUTPUT_DIR,
`/undefined-undefined.gif`
)
expect.assertions(3)
Expand Down
6 changes: 2 additions & 4 deletions packages/gatsby-remark-copy-linked-files/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ const _ = require(`lodash`)
const cheerio = require(`cheerio`)
const imageSize = require(`probe-image-size`)

const DEPLOY_DIR = `public`

const invalidDestinationDirMessage = dir =>
`[gatsby-remark-copy-linked-files You have supplied an invalid destination directory. The destination directory must be a child but was: ${dir}`

Expand All @@ -25,12 +23,12 @@ const newPath = (linkNode, destinationDir) => {
if (destinationDir) {
return path.posix.join(
process.cwd(),
DEPLOY_DIR,
process.env.GATSBY_OUTPUT_DIR,
destinationDir,
newFileName(linkNode)
)
}
return path.posix.join(process.cwd(), DEPLOY_DIR, newFileName(linkNode))
return path.posix.join(process.cwd(), process.env.GATSBY_OUTPUT_DIR, newFileName(linkNode))
}

const newLinkURL = (linkNode, destinationDir) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-source-filesystem/src/extend-file-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = ({ type, getNodeAndSavePathDependency, pathPrefix = `` }) => {
publicURL: {
type: GraphQLString,
args: {},
description: `Copy file to static directory and return public url to it`,
description: `Copy file to static directory and return ${process.env.GATSBY_OUTPUT_DIR} url to it`,
resolve: (file, fieldArgs, context) => {
const details = getNodeAndSavePathDependency(file.id, context.path)
const fileName = `${file.name}-${file.internal.contentDigest}${
Expand All @@ -20,7 +20,7 @@ module.exports = ({ type, getNodeAndSavePathDependency, pathPrefix = `` }) => {

const publicPath = path.join(
process.cwd(),
`public`,
process.env.GATSBY_OUTPUT_DIR,
`static`,
fileName
)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-transformer-sharp/src/extend-node-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ module.exports = ({
}`
const publicPath = path.join(
process.cwd(),
`public`,
process.env.GATSBY_OUTPUT_DIR,
`static`,
imageName
)
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/default-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from "react"
let stylesStr
if (process.env.NODE_ENV === `production`) {
try {
stylesStr = require(`!raw-loader!../public/styles.css`)
stylesStr = require(`!raw-loader!../${process.env.GATSBY_OUTPUT_DIR}/styles.css`)
} catch (e) {
console.log(e)
}
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/cache-dir/static-entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = (locals, callback) => {

let stats
try {
stats = require(`../public/stats.json`)
stats = require(`../${process.env.GATSBY_OUTPUT_DIR}/stats.json`)
} catch (e) {
// ignore
}
Expand Down Expand Up @@ -184,7 +184,7 @@ module.exports = (locals, callback) => {
})

// Add the chunk-manifest at the end of body element.
const chunkManifest = require(`!raw!../public/chunk-manifest.json`)
const chunkManifest = require(`!raw!../${process.env.GATSBY_OUTPUT_DIR}/chunk-manifest.json`)
postBodyComponents.unshift(
<script
id="webpack-manifest"
Expand Down
12 changes: 6 additions & 6 deletions packages/gatsby/src/bootstrap/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ module.exports = async (args: BootstrapArgs) => {
payload: program,
})

// Delete html and css files from the public directory as we don't want
// Delete html and css files from the output directory (default: public) as we don't want
// deleted pages and styles from previous builds to stick around.
let activity = report.activityTimer(
`delete html and css files from previous builds`
)
activity.start()
await del([
`public/*.{html,css}`,
`public/**/*.{html,css}`,
`!public/static`,
`!public/static/**/*.{html,css}`,
`${process.env.GATSBY_OUTPUT_DIR}/*.{html,css}`,
`${process.env.GATSBY_OUTPUT_DIR}/**/*.{html,css}`,
`!${process.env.GATSBY_OUTPUT_DIR}/static`,
`!${process.env.GATSBY_OUTPUT_DIR}/static/**/*.{html,css}`,
])
activity.end()

Expand Down Expand Up @@ -149,7 +149,7 @@ module.exports = async (args: BootstrapArgs) => {
initCache()

// Ensure the public/static directory is created.
await fs.ensureDirSync(`${program.directory}/public/static`)
await fs.ensureDirSync(`${program.directory}/${process.env.GATSBY_OUTPUT_DIR}/static`)

// Copy our site files to the root of the site.
activity = report.activityTimer(`copy gatsby files`)
Expand Down
6 changes: 3 additions & 3 deletions packages/gatsby/src/commands/build-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ module.exports = async (program: any) => {

// We don't want any javascript produced by this step in the process.
try {
fs.unlinkSync(`${directory}/public/bundle-for-css.js`)
fs.unlinkSync(`${directory}/${process.env.GATSBY_OUTPUT_DIR}/bundle-for-css.js`)
} catch (e) {
// ignore.
}

// Ensure there's a styles.css file in public so tools that expect it
// Ensure there's a styles.css file in output directory (default: public) so tools that expect it
// can find it.
fs.ensureFile(`${directory}/public/styles.css`, err => {
fs.ensureFile(`${directory}/${process.env.GATSBY_OUTPUT_DIR}/styles.css`, err => {
resolve(err)
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/build-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ module.exports = async (program: any) => {
if (e) {
return reject(e)
}
const outputFile = `${directory}/public/render-page.js`
const outputFile = `${directory}/${process.env.GATSBY_OUTPUT_DIR}/render-page.js`
if (stats.hasErrors()) {
let webpackErrors = stats.toJson().errors.filter(Boolean)
return reject(
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ module.exports = async function build(program: BuildArgs) {
await apiRunnerNode(`onPreBuild`, { graphql: graphqlRunner })

// Copy files from the static directory to
// an equivalent static directory within public.
// an equivalent static directory within output directory (default: public).
copyStaticDirectory()

let activity
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/develop-html.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = async (program: any) => {
if (e) {
return reject(e)
}
const outputFile = `${directory}/public/render-page.js`
const outputFile = `${directory}/${process.env.GATSBY_OUTPUT_DIR}/render-page.js`
if (stats.hasErrors()) {
let webpackErrors = stats.toJson().errors
return reject(
Expand Down
Loading