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

feat: Make public assets available #1500

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
8 changes: 7 additions & 1 deletion packages/cozy-scripts/config/webpack.config.pictures.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ module.exports = {
{
test: /\.(png|jpe?g|gif)$/i,
include: /cozy-ui\/transpiled\/react(\/|\\)/,
loader: require.resolve('file-loader')
loader: require.resolve('file-loader'),
options: {
// mobile app needs relative path since it uses file://
outputPath: isMobile ? './img' : 'img/',
publicPath: isMobile ? './img' : '/img',
name: `[name]${environment === 'production' ? '.[hash]' : ''}.[ext]`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explain why in the commit message?

},
/*
For public pages, we need to have all used assets into the build/public
Expand Down
2 changes: 1 addition & 1 deletion packages/cozy-scripts/config/webpack.config.public.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function getConfig() {
]

if (useCozyClientJs) {
/* We need to put all assets in the public build folder since
/* We need to put all assets in the public build folder since
public pages will need to have them public */
plugins.push(
new CopyPlugin([
Expand Down
23 changes: 21 additions & 2 deletions packages/cozy-scripts/config/webpack.config.vendors.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const CopyPlugin = require('copy-webpack-plugin')
const SvgoInstance = require('svgo')
const paths = require('../utils/paths')
const fs = require('fs')
const { publicFolderName, shouldAddPublicConfig } = require('./webpack.vars')

const svgo = new SvgoInstance({
plugins: [
Expand Down Expand Up @@ -35,10 +36,28 @@ function optimizeSVGIcon(buffer, path) {
}
}

module.exports = {
plugins: [
function getConfig() {
let plugins = [
new CopyPlugin([
{ from: paths.appVendorAssets(), transform: optimizeSVGIcon }
])
]

if (shouldAddPublicConfig()) {
plugins.push(
new CopyPlugin([
{
from: paths.appVendorAssets(),
to: `${publicFolderName}`,
transform: optimizeSVGIcon
}
])
)
}

return {
plugins
}
}

module.exports = getConfig()