Coder Social home page Coder Social logo

gulp-terser's People

Contributors

a-312 avatar ceremcem avatar duan602728596 avatar irongeek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

gulp-terser's Issues

TypeError in plugin "terser"

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!

Doesnt output to the right folder

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

[Question] No valid exports main exception

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

keep_quoted is not a supported option

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

[BUG] src('/path/', { sourcemaps: true }) not working

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

How to pass terser options?

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:

Solution

my-uglify = (x) ->
    terser({-mangle, +keep_fnames})(x)
    .on \error, gutil.log

This should be added into the documentation.

mangle option not working for function names

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

`module: true` Causes "SyntaxError in plugin 'terser': Unexpected token eof (undefined)"

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.

New dependency name: uglify-es => terser

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.

TypeError in plugin "terser"

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

does not use pre-existing source map

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?

getting error "The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined".

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.

minify: SyntaxError: Unexpected token function

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

libs.js:4 Uncaught TypeError: Cannot set property window of #<Window> which has only a getter

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.
image

So I created a test folder and setup the following:

  1. CMD: npm init -y
  2. CMD: npm i -S gsap gulp gulp-contact gulp-terser gulp-rename
  3. Create gulpfile.js
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
));
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  1. Run gulp build
  2. Create index.html
  3. Add script tag link in head to libs.min.js (will give you console log error).
  4. Comment out script tag from point 6 and add another script tag link in head to ./node_modules/gsap/dist/gsap.min.js (no console errors)

Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.