I have following stucture of the project:
- _build/
- build-tools/
- gulpfile.js
- someFolder/
- excludeFolder/
- index.html
I want to copy all the files except _build and 'excludeFolder' dir to the _build/release directory.
I am using this gulp task:
gulp.src(['*',
'!_build/**/*',
'!build-tools/**/*',
'!excludeFolder/**/*'],{base:'..'})
.pipe(gulp.dest('_build/release'));
How can I command Gulp to start relative path from upper root directory, or any other directory that the gulfile.js is located?
As far as I understand the behavior your looking is cwd, not base
gulp.src([
'**',
'!_build',
'!_build/**',
'!build-tools',
'!build-tools/**',
'!excludeFolder',
'!excludeFolder/**'
],{ cwd:'..' })
.pipe(gulp.dest('_build/release'), { cwd: '..' });
base is a tricky property, which aims to say to gulp where to start copying the files based on the cwd, but that doesn't mean that you can omit the parent folder .. call on gulp.src (your case specifically).
Related
i have a UI Project that grunts the files and copies to the dist folder.
The problem is - the dist folder has some static js files on its own. (for eg library files )
So for eg : my UI folder has 1.js, 2.js
My Dist file has 1.js, 2.js and also lib1.js, lib2.js.
When i run my run copy command, i am expecting to copy 1.js and 2.js and place it in my dist folder - which happens. But what it also does is- it deletes the other files and folders like lib1.js and lib2.js.
Anyway I can only "Overwrite" the files but not delete anything else?
I use the following :
{
expand: true,
cwd: '<%= globalConfig.path.build %>/js/pages/',
src: ['*.js'],
dest: '<%= globalConfig.path.dist %>/js/pages/'
}
I'm trying to use gulp-elm with a monolithic architecture. I have setup my project dir with client and server directories and I've put my gulp file in the main directory. The directory structure is pretty simple.
project/
gulpfile.js
package.json
client/
elm-package.json
server/
...
When i run, for example,
gulp elm-init
with the following task:
// File paths
var paths = {
dest: 'client/dist',
elm: 'client/src/*.elm',
static: 'client/src/*.{html,css}'
};
// Init Elm
gulp.task('elm-init', function(){
return elm.init({ cwd : 'client' });
});
// Compile Elm to HTML
/*gulp.task('elm', ['elm-init'], function(){
return gulp.src(paths.elm)
.pipe(plumber())
.pipe(elm({ cwd : 'client' }))
.pipe(gulp.dest(paths.dest));
});*/
the elm-stuff folder and elm-package.json get moved to the main project directory. Is this expected? if not, is there a correct way to use a gulpfile from the parent directory to build an elm package in a nested directory? I think my effort matches the example.
gulp.task('init-nested', function(){
return elm.init({cwd: 'elm/nested-elm/'});
});
gulp.task('nested', ['init-nested'], function(){
return gulp.src('elm/nested-elm/*.elm')
.pipe(elm.make({filetype: 'html', cwd: 'elm/nested-elm/'}))
.pipe(gulp.dest('dest/'));
});
I've tried looking at the source, as well as following dependencies to see if i could figure it out myself, but i'm relatively unfamiliar with node so it's hard for me to figure out exactly what's going on in the gulp-elm source (as well as one of the deps i checked out.)
I was using this tutorial by Auth0 which had an old version of gulp-elm in package.json. Ugh!
Consider this which checks for JS files in either of two specific locations:
gulp.src( "#(Branch|Main)/*.js" ).pipe( _do-stuff_ )
How does one get which folder was matched (Main or Branch) for the current file(s)?
file structure
assets/js/
- build/
- plugin/
jquery.min.js
- src/
index.js
config.js
builds.js
require.js
assets/js/src/index.js
requirejs(['jquery']);
assets/js/config.js
requirejs.config({
baseUrl: './',
paths: {
jquery: 'plugin/jquery.min'
}
})
If I want to use r.js to optimize the file, just execute r.js -o config.js name=src/index out=build/index.js, the r.js will compile a file into build/index.js with optimization and dependency, but there will be many files need to compile in the future, so I create a builds.js
assets/js/builds.js
({
appDir: 'src',
dir: 'build',
mainConfigFile: 'config.js',
modules: [
{name: 'index'}
]
})
If I run r.js -o builds.js, I will got wrong path message.
Error: Error: ENOENT: no such file or directory, open 'D:\www\r\build\plugin\jquery.min.js'
I need to go back to config.js, and edit the path relative to src.
requirejs.config({
baseUrl: './',
paths: {
jquery: '../plugin/jquery.min'
}
})
It will work, but is it possible to write one config file for both purpose?
Specify paths again in the build file, relative to /src.
builds.js
({
appDir: 'src',
baseUrl: './',
dir: 'build',
modules: [
{name: 'index'}
],
paths: {
jquery: '../plugin/jquery.min'
}
})
The paths in the build file work differently than in the config file.
The appDir option of /src specifies that all your scripts are located in /src, however your config.js and folder structure have the /plugins outside of /src.
When the jquery path is resolved, the paths in the config.js file are used because the mainConfigFile option is used.
All module paths would need to be redefined in your build file in addition to your config file. This is because all module paths are resolved relative to the baseUrl, which is in relation to the appDir in the build file – this is the confusing bit.
Reference the following r.js example build file. https://github.com/jrburke/r.js/blob/master/build/example.build.js
The official doc on the RequireJS optimizer contains a helpful section about path resolution.
http://requirejs.org/docs/optimization.html#basics
Relative path resolution rules:
In general, if it is a path, it is relative to the build.js file used to hold the build options, or if just using command line arguments, relative to the current working directory. Example of properties that are file paths: appDir, dir, mainConfigFile, out, wrap.startFile, wrap.endFile.
For baseUrl, it is relative to appDir. If no appDir, then baseUrl is relative to the build.js file, or if just using command line arguments, the current working directory.
For paths and packages, they are relative to baseUrl, just as they are for require.js.
In the Intern config file (default-conf.js, etc.), there's a packages section for the loader:
packages: [ { name: 'intern-selftest', location: '.' } ]
It specifies relative paths to each package. But what are those paths relative to?
the directory node is run from
the location of the config file
the location of client.html / runner.js (i.e. the intern directory)
somewhere else?
The runsauce.sh works for me but in that case, node is run from the intern directory. (A related question: does node need to be run from a certain directory?)
I've seen Intern and client paths in version 1.1.0; not sure if that's still necessary.
The paths are relative to loader.baseUrl, which in Intern 1.3 by default is the current working directory (command-line) or two levels above the client.html (browser).