duan602728596 / gulp-terser Goto Github PK
View Code? Open in Web Editor NEWgulp plugin, compressed es6+ code.
License: MIT License
gulp plugin, compressed es6+ code.
License: MIT License
Hi, any idea why this error is happening?
[17:24:11] TypeError in plugin "terser" Message: The first argument must be of type string or an instance of Buffer, ArrayBuffer, or Array or an Array-like Object. Received undefined Details: code: ERR_INVALID_ARG_TYPE domainEmitter: [object Object] domainThrown: false
when using the following code, which worked 2 weeks ago:
gulp.task('build:scripts', function () { return gulp.src(config.app_files.js) .pipe(sourcemaps.init()) .pipe(rollup({ }, { format: 'cjs', strict: false })) .pipe(concat('script.js')) .pipe(terser()) .pipe(rename(function (path) { path.extname = ".min.js" })) .pipe(sourcemaps.write('.', { mapFile: function (mapFilePath) { return mapFilePath.replace('.js.map', '.map'); } })) .pipe(gulp.dest(config.build_dir)); });
Thanks!
The following code should take the file from js/
folder and write it into build/js/
but it writes it to ./build
root.
const gulp = require('gulp');
const terser = require('gulp-terser');
gulp.task('default', function (callback) {
return gulp.src('./js/index.js')
.pipe(terser())
.pipe(gulp.dest('./build'));
});
I know I could change to where it writes, the bigger problem arises when you have multiple folders with JS code and use: **/*.js
and then doesnt write to the corresponding folders.....
Here is a tiny demo: gulp-terser.zip
I keep on getting the following error when doing any yarn
add/remove operations:
warning [email protected]: The engine "terser" appears to be invalid.
Is there something that I'm missing?
Apologies if this is a very simple solution! Just starting out with gulp. When I run the how to use example, I get the following exception:
Error: No valid exports main found for '----/node_modules/terser'
at resolveExportsTarget (internal/modules/cjs/loader.js:625:9)
at applyExports (internal/modules/cjs/loader.js:502:14)
at resolveExports (internal/modules/cjs/loader.js:551:12)
at Function.Module._findPath (internal/modules/cjs/loader.js:657:22)
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:960:27)
at Function.Module._load (internal/modules/cjs/loader.js:855:27)
at Module.require (internal/modules/cjs/loader.js:1033:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (------/node_modules/gulp-terser/lib/index.js:7:38)
at Module._compile (internal/modules/cjs/loader.js:1144:30) {
code: 'MODULE_NOT_FOUND'
Can anyone advise whats causing this?
node v13.6.0
So I'm trying to use gulp-terser and which to use the keep_quoted
like::
function terser() {
return gulp.src('js/**/*.js')
.pipe(gTerser({
keep_fnames: false,
keep_quoted: true, // <====== doesn't work here
mangle: {
keep_quoted: true, // <==== neither here
properties: true,
keep_fnames: false,
}
}))
.pipe(gulp.dest(`${destStatic}/js/`))
}
but sadly keep getting error: keep_quoted is not a supported option
+--------------------
+-- VERSIONS
+--------------------
+-- [email protected]
+-- [email protected]
+-- [email protected]
+--------------------
Hello,
I switched from gulp-uglifyes to gulp-terser but i got this error:
TypeError: Cannot read property 'file' of undefined
at DestroyableTransform._transform (/%project_path%/node_modules/gulp-terser/lib/index.js:41:30)
Any clue?
Thank you very much,
Alban
const minifyDistJs = () => src(paths.dist.js + '/adminlte.js', { sourcemaps: true })
.pipe(terser({
compress: {
passes: 2
}
}))
.pipe(rename({ suffix: '.min' }))
.pipe(dest(paths.dist.js), { sourcemaps: '.' })
not creating sourcemaps
I'm using gulp-terser
with additional terser
options and my gulpfile
is as follows:
require! 'gulp-terser': terser
my-uglify = (x) ->
terser x, {-mangle, +keep_fnames}
.on \error, gutil.log
gulp.task \browserify, ->
get-bundler file
.bundle!
...
.pipe if-else optimize-for-production, my-uglify
It turns out, gulp-terser
is a factory function, so the solution is:
my-uglify = (x) ->
terser({-mangle, +keep_fnames})(x)
.on \error, gutil.log
This should be added into the documentation.
Unlike gulp-uglify, gulp-terser does not have support for gulp-sourcemaps, but instead garbles outputted sourcemaps.
Can this be added?
This plugin uses terser 5.9.0 which is insecure, see: GHSA-4wf5-vphf-c2xc
I have a basic JS file here:
function helloworld(someparameter)
{
console.log("Hello World");
return someparameter;
}
I also have this basic gulp task:
function minifyJs(cb) {
pump([
gulp.src("public/**/*.js"),
terser(),
gulp.dest("public")
], cb);
}
By default according to
https://github.com/terser-js/terser#minify-options
This should mangle and not keep function names or anything. But it creates this:
function helloworld(l){return console.log("Hello World"),l}
This is keeping function names?
I also explicity set keep_fnames to false but still nothing
Where Module.js
is an ES6 module,
gulp.src('Module.js')
.pipe(gulpTerser({module: true}))
.pipe(gulp.dest('public/js'))
results in
SyntaxError in plugin "terser"
Message:
Unexpected token: eof (undefined)
Details:
filename: 0
...
while
gulp.src('script.js')
.pipe(gulpTerser())
.pipe(gulp.dest('public/js'))
does not.
Upgrading terser to latest (5.5.1) appears to resolve.
There has been development on a new fork of uglify-es, which is now called terser and has its own package!
"terser": "^3.7.3"
Please upgrade to our new version.
Suddenly running into the following error with gulp
[11:15:25] TypeError in plugin "terser"
[INFO] Message:
[INFO] The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
[INFO] Details:
[INFO] code: ERR_INVALID_ARG_TYPE
[INFO] domainEmitter: [object Object]
[INFO] domainThrown: false
[INFO]
[INFO] [11:15:25] 'build' errored after 1.35 s
[INFO] npm ERR! code ELIFECYCLE
Running version "gulp-terser": "~1.2.0"
Node version v12.14.0
Possibly related to Issue #14
Getting an error:
TypeError in plugin "terser"
Message:
Cannot read property 'isPromise' of undefined
Configuration:
gulp
.src(files.js.src)
.pipe(terser())
.on('error', function (error) {
console.error('Error in js.src compress task', error.toString());
})
.pipe(concat('admin.min.js'))
.pipe(gulp.dest(path.js.build));
Versions:
[email protected]
[email protected]
[email protected]
[email protected]
This repo doesn't appear to have a changelog or releases, other than those listed on https://www.npmjs.com/package/gulp-terser. Are changes per release listed anywhere? I had to look into the commit for the latest release.
I am trying to use gulp-terser to run terser against js files that were compiled from TypeScript. The TypeScript compiler generated sourcemaps when it ran, and in this source map, "sources" lists my .ts file, as I would expect. When gulp-terser runs, however, it's as if the source map is generated from scratch. "sources" ends up listing the .js file instead of the original .ts file as expected.
Looking at the code, I don't see terser's sourceMap.content being set from chunk.sourceMap. Only sourceMap.filename is set. The terser doc says "The value of filename is only used to set file attribute (see the spec) in source map file.... If you're compressing compiled JavaScript and have a source map for it, you can use sourceMap.content".
Does this plugin support source maps that were previously loaded?
Please & thanks!
error:
Plumber found unhandled error:
TypeError [ERR_INVALID_ARG_TYPE] in plugin "terser"
Message:
The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
I am using this code:
const gulp = require('gulp');
const terser = require('gulp-terser');
gulp.task('default', function() {
return gulp.src(['js/*.js'])
.pipe(plumber())
.pipe(terser())
.pipe(gulp.dest('../assets/js'));
});
I also tried to pass {ecma:8} in terser as .pipe(terser({ecma:8}))
but it doesn't resolve the problem.
I have faced a issue when running v1.3.2 at node_modules/terser/dist/bundle.min.js:23478
Location of the error:
async function minify(files, options)
Error message:
SyntaxError: Unexpected token function
Please update published version in registry.
fix: unhandled promise rejection error
(committed on 14 Sep ) is not presented in "built" version that's installed on npm install
.
1.4.0 tag was created on 23 Aug.
Using some libs after gulp-terser is run js errors are caused:
libs.js:4 Uncaught TypeError: Cannot set property window of # which has only a getter.
So I created a test folder and setup the following:
const gulp = require("gulp");
const concat = require('gulp-concat');
const terser = require('gulp-terser');
let jsFiles = [
"./node_modules/gsap/dist/gsap.js",
];
let buildLibsProd = function (done) {
gulp.src(jsFiles)
.pipe(concat('libs.min.js'))
.pipe(terser())
.on("error", function (e) {
console.log(e.toString());
this.emit("end");
})
.pipe(gulp.dest('./'));
done();
};
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
gulp.task("build", gulp.parallel(
buildLibsProd
));
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Any ideas?
gulp.src(source, { base, sourcemaps })
.pipe(tsProject())
.pipe(gulpIf(!!minify, terser({ safari10: true })))
.pipe(gulp.dest(target, this.returnSourcemaps(sourcemaps)))
.on('end', () => resolve(true))
With [email protected]
& [email protected]
, got this error message.
Need help.
For example, I have wrapped terser
with my customized logic, and exported a same interface. With gulp-uglify
, I can use its composer.js
to call my API, but gulp-terser
always use require('terser')
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.