Encore Webpack - Copy folders structure with copy-webpack-plugin - symfony

I'm using Symfony 5 and copy-webpack-plugin. I would like copy this structure from assets/fonts to public/build/fonts :
assets
----fonts
--------folder1
------------subFolder1.1
----------------file1.1.1
----------------file1.1.2
------------file1.2
------------file1.3
--------folder2
------------subFolder2.1
----------------file2.1.1
----------------file2.1.2
------------file2.2
------------file2.3
--------file3
--------file4
I have this webpack configuration :
const CopyWebpackPlugin = require('copy-webpack-plugin');
.addPlugin(new CopyWebpackPlugin(
[{
patterns: [{
from: '**/*.*',
to: 'fonts',
context: './fonts',
force: true
}]
}],
{
copyUnmodified: true
}
))
However, it doesn't work. I tried a lot of different configurations, to no avail.

Related

Is there any way to use #next/env in codegen.yaml?

I was wondering if there was a way to use #next/env to replace variables in codegen.yaml when i run yarn codegen:
graphql-codegen -r dotenv/config --config codegen.yml - this is codegen example to load dot env
graphql-codegen -r #next/env --config codegen.yml - this is what i want to achieve
When i call it, i get
${SERVER_API_URL}/graphql goes as undefined/graphql
My usecase is:
# .env
HOST=https
API_DOMAIN=example.com
SERVER_API_URL=$HOST://$API_DOMAIN
# codegen.yaml
schema: ${SERVER_API_URL}/graphql
Why use #next/env? it replaces variables in .env, i'm attaching documentation sample from next.js documentation:
Note: Next.js will automatically expand variables ($VAR) inside of
your .env* files. This allows you to reference other secrets, like so:
# .env
HOSTNAME=localhost
PORT=8080
HOST=http://$HOSTNAME:$PORT
If you are trying to use a variable with a $ in the actual value, it needs to be escaped like so: \$.
For example:
# .env
A=abc
# becomes "preabc"
WRONG=pre$A
# becomes "pre$A"
CORRECT=pre\$A
source: https://nextjs.org/docs/basic-features/environment-variables#loading-environment-variables
You can't use #next/env directly via -r flag. However you still have couple of alternatives. For example, you can address the required .env file directly:
DOTENV_CONFIG_PATH=./.env.local graphql-codegen --config codegen.yml -r dotenv/config
If you still want to use #next/env, you can convert your codegen.yml to codegen.js and import #next/env. For example, my original YML:
overwrite: true
schema:
- https://graphql.fauna.com/graphql:
headers:
Authorization: 'Bearer ${FAUNA_ADMIN_KEY}'
documents: null
generates:
src/generated/graphql.ts:
plugins:
- typescript
- typescript-operations
- typescript-graphql-request
./graphql.schema.json:
plugins:
- 'introspection'
I re-wrote it as JS:
const { loadEnvConfig } = require('#next/env')
loadEnvConfig(process.cwd())
module.exports = {
overwrite: true,
schema: {
'https://graphql.fauna.com/graphql': {
headers: {
Authorization: `Bearer ${process.env.FAUNA_ADMIN_KEY}`,
},
},
},
documents: null,
generates: {
'src/generated/graphql.ts': {
plugins: [
'typescript',
'typescript-operations',
'typescript-graphql-request',
],
},
'./graphql.schema.json': { plugins: ['introspection'] },
},
}
and then generated the code using graphql-codegen --config codegen.js.
Here is an issue on Github that helped me.

grunt rpm create a symlink

I have this grunt file that creates a rpm package for me, how can I create a symlink like this for an example:
link("/usr/local/bin/tams-cli", "/opt/tams-cli/tams-cli.js")
Have not been able to to find that, here below is my source code.
grunt.initConfig({
pkg: grunt.file.readJSON('./package.json'),
easy_rpm: {
options: {
buildArch,
rpmDestination: './built/',
},
release: {
files: [
{
src: ['node_modules/**/*',
'js/**/*',
'cfg/*',
'package.json',
'readme.md',
],
dest: '/opt/tams-cli',
},
{
src: 'tams-cli.js',
dest: '/opt/tams-cli',
mode: 0550,
}
],
excludeFiles: [
'tmp-*',
'./built',
],
},
},
To create the symlink after the rpm package is installed utilize the postInstallScript option in your easy_rpm task. The description for the postInstallScript reads:
postInstallScript
Array<String>
An array of commands to be executed after the installation. Each element in the array represents a command.
In the Gruntfile.js excerpt below it utilizes the ln command to create the symlink using the additional two options:
-s to make a symbolic link instead of a hard link.
-f to remove existing destination files if they exist already.
Gruntfile.js
grunt.initConfig({
// ...
easy_rpm: {
options: {
postInstallScript: ['ln -s -f /opt/tams-cli/tams-cli.js /usr/local/bin/tams-cli'],
// ..
},
// ...
},
// ...
});

OracleJET: How to change grunt release directory

I created an javascript app using Oracle JET v2.0. Running
grunt build:release
creates release folder in the project root folder. How to change this to point to another path, for example outside project root?
If you're using the Yeoman generator, you can follow the Grunt flow in scripts/grunt/tasks/build.js. You'll see under if (target === "release")
that it runs a number of tasks in order.
Unfortunately the release folder name is hardcoded in many of those tasks' config files. So it might make more sense to add a task at the end of your build:release task to copy the built release into a new directory. You could add a target to the scripts/grunt/config/copy.js file named myFinalRelease:
module.exports = {
release:
{
src: [
"**",
"!bower_components/**",
"!grunt/**",
"!scripts/**",
"!js/**/*.js",
"js/libs/**",
"!js/libs/**/*debug*",
"!js/libs/**/*debug*/**",
"!node_modules/**",
"!release/**",
"!test/**",
"!.gitignore",
"!bower.json",
"!Gruntfile.js",
"!npm-shrinkwrap.json",
"!oraclejetconfig.json",
"!package.json"
],
dest: "release/",
expand: true
},
myFinalRelease:
{
cwd: 'release/',
src: ['**'],
dest: "myRelease",
expand: true
}
};
Then add that task:target as a copy step on the last line of the release section of scripts/grunt/tasks/build.js:
...
if (target === "release")
{
grunt.task.run(
[
"clean:release",
"injector:mainReleasePaths",
"uglify:release",
"copy:release",
"requirejs",
"clean:mainTemp",
"copy:myFinalRelease"
]);
}
...
To make this more robust, you should do some additional cleanup tasks if you're doing a lot of build:release'ing, because the myRelease folder won't get cleaned out unless you create tasks to do it. Or you might look into other Grunt plugins like grunt-contrib-rename.
If this is too much copying and too messy for your tastes, you could instead edit all of the hardcoded task configs to change the name of the release directory. You'll find the directory name shows up in these four files:
scripts/grunt/config/clean.js
...
release: ["release/*"],
...
scripts/grunt/config/uglify.js
...
dest:"release/js"
...
scripts/grunt/config/copy.js
...
dest: "release/",
...
scripts/grunt/config/require.js
...
baseUrl: "./release/js",
name: "main-temp",
mainConfigFile: "release/js/main-temp.js",
optimize: "none",
out: "release/js/main.js"...
...

Grunt less source maps change path prefix

My config
server: {
options: {
sourceMap: true,
sourceMapFilename: '.tmp/styles/main.css.map',
sourceMapURL: '/styles/main.css.map'
},
files: {
'.tmp/styles/main.css':
'src/app/views/styles/application.less'
}
},
My structure
.tmp
src
Gruntfile.js
so after calling grunt less:server
I am getting .tmp/styles/main.css.map
with attr "sources" everywhere src/ prefix
but I want without src/ because server starts from src/*
How can I change it ?
Since version 1.0.0. grunt-contrib-less accepts the same options as the command line compiler does. You can get a list of these options by running lessc wihtout any argument on your command line:
--source-map-rootpath=X Adds this path onto the sourcemap filename and less file paths.
So you should use:
options: {
sourceMap: true,
sourceMapFilename: '.tmp/styles/main.css.map',
sourceMapURL: '/styles/main.css.map',
sourceMapRootpath: "/app/views/styles/"
}

Requirejs optimization with grunt

I am trying to create a requirejs optimization config with grunt and almond. Here's the config:
requirejs:
build:
options:
almond: true
dir: 'build'
appDir: ''
baseUrl: '../client'
wrap: true
include: '../client/main'
keepBuildDir: true
paths:
underscore: 'client/vendor/underscore'
jquery : 'client/vendor/jquery'
backbone : 'client/vendor/backbone'
Folder Structure:
Error:
C:\Users\User\Documents\Source\Project>grunt requirejs
Running "requirejs:build" (requirejs) task
>> Error: ENOENT, no such file or directory
>> 'C:\Users\User\Documents\Source\Project\build\models\MenuItem.js'
>> In module tree:
>> ../client/main
Warning: RequireJS failed. Use --force to continue.
Main.js code (written in coffeescript)
requirejs.config(
baseUrl: "client"
shim:
'backbone':
deps: ['jquery']
exports: 'Backbone'
'jquery':
exports: '$'
'underscore':
exports: '_'
paths:
jquery: 'vendor/jquery-1.11.0'
underscore: 'vendor/underscore'
backbone: 'vendor/backbone'
)
define 'start', ()->
window.types =
Models: {}
Collections: {}
Views: {}
null
require ['models/MenuItem', 'views/MenuItem'], (MenuItemModel, MenuItemView)->
view = new MenuItemView(
new MenuItemModel(),
"#app",
'first'
)
view.render();
null
I want to compile my entire project spread across multiple js files into a single file in a way that requirejs would not be needed. I am trying to do this using almond js but the build task does not look for referenced files relative to the path of referring file. Please help me with the correct configuration.

Resources