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

Strapi #178

Merged
merged 19 commits into from
Nov 21, 2023
Merged

Strapi #178

merged 19 commits into from
Nov 21, 2023

Conversation

TriPSs
Copy link
Owner

@TriPSs TriPSs commented Nov 20, 2023

No description provided.

BREAKING CHANGE: The build implementation changed causing the `src/admin/webpack.config.js` to be updated with `withNx`.
See [webpack.config.js.template](./packages/strapi/src/generators/init/files/src/admin/webpack.config.js.template).
Also the `tsConfig` option is now required.
@TriPSs
Copy link
Owner Author

TriPSs commented Nov 20, 2023

@joshuaellis would you be willing to check the Strapi implementation? It consists of these two files:

export async function buildExecutor(
options: BuildExecutorSchema,
context: ExecutorContext
): Promise<{ success: boolean }> {
const { root } = context.workspace.projects[context.projectName]
if (!options.outputPath) {
throw new Error('No "outputPath" defined in options!')
}
if (!options.tsConfig) {
throw new Error('No "tsConfig" defined in options!')
}
const distDir = join(process.cwd(), options.outputPath)
// Set the env vars
Object.keys(options.envVars || {}).forEach(function (key) {
if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
process.env[key] = options.envVars[key]
}
})
const strapiRoot = join(workspaceRoot, options.root || root)
const tsConfig = loadTsConfig(workspaceRoot, options.tsConfig)
// nodeBuild somehow only compiles the admin panel
await tsUtils.compile(strapiRoot, {
watch: false,
configOptions: {
options: {
incremental: true,
outDir: distDir
}
}
})
await nodeBuild({
ignorePrompts: true,
minify: Boolean(options.production),
cwd: strapiRoot,
logger: createStrapiLogger(),
tsConfig
})
await createPackageJson(
options.outputPath,
strapiRoot,
context,
options.generateLockFile
)
await copyFolderSync(`${strapiRoot}/public`, `${distDir}/public`)
await copyFavicon(`${strapiRoot}`, distDir)
await copyFavicon(`${strapiRoot}/public`, distDir)
return { success: true }
}

And an withNx to use inside the webpack config as follows, this will make sure the output directory is correctly set entrypoint to the correct location of app.js

'use strict'

const { withNx } = require('@nx-extend/strapi')

module.exports = (config, webpack) => {
  return withNx(config, webpack)
}

import { parseTargetString, workspaceRoot } from '@nx/devkit'
import { readCachedProjectGraph } from '@nx/workspace/src/core/project-graph'
import { FsTree } from 'nx/src/generators/tree'
import { getProjects } from 'nx/src/generators/utils/project-configuration'
export function withNx(config: any, webpack: any) {
const nxTree = new FsTree(workspaceRoot, false)
const projects = getProjects(nxTree)
const project = projects.get(process.env.NX_TASK_TARGET_PROJECT)
if (!project) {
throw new Error('Project not found!')
}
const target = project.targets[process.env.NX_TASK_TARGET_TARGET]
const isServing = target.executor === '@nx-extend/strapi:serve'
// We don't want to any of the below things when we are serving
if (!isServing) {
let options = target.options
if (process.env.NX_TASK_TARGET_CONFIGURATION && process.env.NX_TASK_TARGET_CONFIGURATION in target.configurations[process.env.NX_TASK_TARGET_CONFIGURATION]) {
options = {
...options,
...target.configurations[process.env.NX_TASK_TARGET_CONFIGURATION]
}
}
let outputPath = options.outputPath
if (!outputPath && options.buildTarget) {
const buildTarget = parseTargetString(options.buildTarget, readCachedProjectGraph())
outputPath = projects.get(buildTarget.project).targets[buildTarget.target].options.outputPath
}
if (!outputPath) {
throw new Error('No "outputPath" option found!')
}
const root = options.root || project.root
config.entry.main = [workspaceRoot + `/${root}/.strapi/client/app.js`]
config.output.path = workspaceRoot + `/${outputPath}/build`
}
return config
}

@TriPSs TriPSs linked an issue Nov 20, 2023 that may be closed by this pull request
@TriPSs
Copy link
Owner Author

TriPSs commented Nov 20, 2023

Directly trying to finally get the E2E test to run inside the CI 😅

@TriPSs TriPSs merged commit cd25928 into master Nov 21, 2023
2 of 3 checks passed
@TriPSs TriPSs deleted the strapi branch November 21, 2023 07:53
@joshuaellis
Copy link

For these bits:

     config.entry.main = [workspaceRoot + `/${root}/.strapi/client/app.js`] 
     config.output.path = workspaceRoot + `/${outputPath}/build` 

you might be better off trying to utilise the existing paths and see if you can mutate them into what you want, but i think that would be a nice to have :)

@TriPSs
Copy link
Owner Author

TriPSs commented Nov 21, 2023

@joshuaellis good one, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Strapi: Error when building from workspace root
2 participants