Project

General

Profile

Actions

Bug #24043

closed

Uglifier fails to precompile plugin assets written in JQuery

Added by Tristan Robert almost 6 years ago. Updated almost 6 years ago.

Status:
Rejected
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Difficulty:
Triaged:
Fixed in Releases:
Found in Releases:

Description

Hello,

I develop a plugin. I need to add javascript code in assets files to be used by my views.

Plugin assets added in my_plugin are located in app/assets/javascripts/my_plugin/plugin.js.

It contains JQuery code:

import $ from 'jquery';
import { showSpinner } from '../foreman_tools';

export function storageSelected(item) {
...
}

When I precompile my assets:

bundle exec bin/rake plugin:assets:precompile[my_plugin]

Result is:

Running via Spring preloader in process 332
rake aborted!
Uglifier::Error: Unexpected token: name ($). To use ES6 syntax, harmony mode must be enabled with Uglifier.new(:harmony => true).
/home/tristan/Documents/src/foreman/lib/tasks/plugin_assets.rake:76:in `block in compile'
/home/tristan/Documents/src/foreman/lib/tasks/plugin_assets.rake:75:in `compile'
/home/tristan/Documents/src/foreman/lib/tasks/plugin_assets.rake:122:in `block in <top (required)>'
-e:1:in `<main>'
Tasks: TOP => plugin:assets:precompile
(See full trace by running task with --trace)

I have added in engine.rb:

initializer 'my_plugin.configure_assets', group: :assets do
      SETTINGS[:my_plugin] = { 
        assets: { 
          precompile: assets_to_precompile 
        }, :js_compressor => Uglifier.new(harmony: true) }
    end

Result is still the same.

When I change the line 56 in foreman/lib/tasks/plugin_assets.rake:

env.js_compressor = :uglifier

with:

env.js_compressor = Uglifier.new(harmony: true)

It finally works.

Actions #1

Updated by Tristan Robert almost 6 years ago

  • Status changed from New to Rejected

My js file is not well formatted. I fixed it and it works. Sorry, you can forget this bug false positive.

Actions

Also available in: Atom PDF