Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to config less options #907

Closed
vdfor opened this issue Feb 28, 2018 · 40 comments
Closed

How to config less options #907

vdfor opened this issue Feb 28, 2018 · 40 comments
Labels

Comments

@vdfor
Copy link

vdfor commented Feb 28, 2018

When using less3, how to enable inline javaScript?

@parcel-bundler parcel-bundler deleted a comment from vdfor Feb 28, 2018
@davidnagli
Copy link
Contributor

Just moved the description from the seperate comment into the issue body...

@chenshuai2144
Copy link

lessrc no working

@davidnagli
Copy link
Contributor

@chenshuai2144 Please open a separate issue

@vdfor We don’t support inline JavaScript yet

@chenshuai2144
Copy link

I think it should be able to turn on this function in lessrc

@BeliefRC
Copy link

less3.0.1 no working,but less2.7.3 is working

@schtr4jh
Copy link

schtr4jh commented May 5, 2018

Encountered same problem, all you have to do is add --js flag to lessc command: lessc --js foo.less > bar.css

@y-takey
Copy link

y-takey commented May 23, 2018

@schtr4jh Thank you very much :) you saved me!
By the way, Is there way that add --js option on parcel automatically? I want to avoid execution lessc command manualy.

@schtr4jh
Copy link

@y-takey I landed here because of some other issue, unrelated to parcel. As far as I know this is something that's changed in some of latest versions of lessc compiler. Maybe you can downgrade lessc if it's installed globally? Or prepare pr that fixes it. :P

@y-takey
Copy link

y-takey commented May 23, 2018

@schtr4jh Thanks for the quick response! I'll try to downgrade lessc.

@DeMoorJasper
Copy link
Member

DeMoorJasper commented May 23, 2018

What about adding:

{
  "inlineJavaScript": true
}

to .lessrc?

According to the less docs this should re-enable the deprecated inlining feature.
As this is deprecated I don't think this should be the default on parcel

@y-takey
Copy link

y-takey commented May 24, 2018

@DeMoorJasper Thanks for the advice! (and sorry for the delay) I've tried it, but i can't work well :(

As this is deprecated I don't think this should be the default on parcel

yes, I agree too.

@viztor
Copy link

viztor commented Jul 6, 2018

Is this fixed? I've been trying to use Antd's babel-plugin-import with Parcel, but doesn't seems to be helpful

@PierrickGT
Copy link

I've managed to make it work using almost the same config than the one in the example available here : https://github.com/ant-design/parcel-antd

I've setup HMR so in my case, I needed to have the following .babelrc config to make the project work.

{
    "presets": [
      "react",
      "env"
    ],
    "plugins": [
        "react-hot-loader/babel",
        "transform-class-properties",
        ["import", {
          "libraryName": "antd",
          "libraryDirectory": "es",
          "style": true
        }]
    ]
}

@viztor
Copy link

viztor commented Jul 15, 2018

The problem is primarily with Less v3. I downgraded it and it worked. but it still requires fixing as we won't be able to stay v2.7 forever

scharf added a commit to moxb/moxb that referenced this issue Aug 9, 2018
@lxwbr
Copy link

lxwbr commented Aug 20, 2018

Having the same problem, have to stay on 2.7.3 for now. Hopefully this will be fixed soon.

@DeMoorJasper
Copy link
Member

DeMoorJasper commented Aug 20, 2018

As this is a deprecated feature of less, I don't think parcel should fix this.

If anyone could open a decent issue with an example repo and such someone might have a look at it. Gonna close this for now.

I don't even think less even supports this at all anymore, the inlineJavascript flag seems to have been removed from the config

@fourcolors
Copy link

It would be nice if there was a flag that enabled this since there are still a ton of libs out there that have inline js. Antd for instance "should" upgrade but I'm having to downgrade to use their lib. It might be too soon to completely ditch it but it's an edge case that should be supported.

@moodseller
Copy link

moodseller commented Feb 22, 2019

Solution for webpack example:


	loader: 'less-loader',
		options: {
			javascriptEnabled: true
		}

@urwork
Copy link

urwork commented Mar 14, 2019

seems .lessrc take no effect

@msereniti
Copy link

Why issue is closed? The problem still exists

@djamaile
Copy link

v3 still does not work in 2019. Is using version 2.7.1 really the only work around?

@entrptaher
Copy link

entrptaher commented May 22, 2019

Apperently the LessAsset does not read the .lessrc file at all. I have zero clues at this moment.

However the fix was just one line one file.
image

I extracted the code and published as a npm module till they somehow fix it in future. Steps to follow:

yarn add -D parcel-plugin-less-js-enabled

Before:

➜  experiment-parcel-antd git:(master) ✗ yarn start
yarn run v1.13.0
$ parcel src/index.html
Server running at http://localhost:1234 
🚨  node_modules/antd/lib/form/style/index.less: Inline JavaScript is not enabled. Is it set in your options?

Now:

➜  experiment-parcel-antd git:(master) ✗ yarn start
yarn run v1.13.0
$ parcel src/index.html
Server running at http://localhost:1234 
✨  Built in 343ms.

@gabrielnoal
Copy link

gabrielnoal commented May 22, 2019

I have fixed this problem just changing "style":true at .babelrc antd import for "style": "css".

before

.babelrc

{
  "plugins": [
    "@babel/plugin-proposal-class-properties",
    ["import", { "libraryName": "antd", "style": true }],
  ]
}

Print screen
image

after

{
  "plugins": [
    "@babel/plugin-proposal-class-properties",
    ["import", { "libraryName": "antd", "style": "css" }],
  ]
}

Print screen
image

PS: I dont't know if this fix will break something later, but it works for now 👍

@y-takey
Copy link

y-takey commented Jun 20, 2019

I got works correctly!

my environment:

parcel-bundler: 1.12.3
less: 3.9.0
less-loader: 5.0.0
(antd: 3.19.5)

<project root>/.lessrc

{
  "javascriptEnabled": true
}

NOT "inlineJavaScript"

<project root>/src/index.less

@import "~antd/dist/antd.less";

@primary-color: #4caf50;

@wangyongf
Copy link

I got works correctly!

my environment:

parcel-bundler: 1.12.3
less: 3.9.0
less-loader: 5.0.0
(antd: 3.19.5)

<project root>/.lessrc

{
  "javascriptEnabled": true
}

NOT "inlineJavaScript"

<project root>/src/index.less

@import "~antd/dist/antd.less";

@primary-color: #4caf50;

It workded for me too, thanks~

@ivanfilhoz
Copy link

Same here. It works!

@imanish003
Copy link

imanish003 commented Sep 8, 2019

Solution for webpack example:


	loader: 'less-loader',
		options: {
			javascriptEnabled: true
		}

This solution worked for me

@chengsokdara
Copy link

chengsokdara commented Nov 12, 2019

@y-takey your solutions doesn't work for me.

I tried below setup and it works for me. But I don't know if this is correct way, because I want to use the options style: true and libraryDirectory: "es" in .babelrc

package.json

"devDependencies": {
  "@babel/core": "^7.7.2",
  "babel-plugin-import": "^1.12.2",
  "less": "^3.10.3",
  "parcel-bundler": "^1.12.4"
},
"dependencies": {
  "antd": "^3.25.1",
  "react": "^16.11.0",
  "react-dom": "^16.11.0"
}

.babelrc

{
  "plugins": [
    [
      "import",
      {
        "libraryName": "antd"
      },
      "antd"
    ]
  ]
}

.lessrc

{
  "javascriptEnabled": true
}

public/index.less

@import "../node_modules/antd/dist/antd.less";
@primary-color: purple;

@entrptaher
Copy link

I came back from the future for another project, and parcel-bundler is still not fixed. The only thing works with parcel is the one plugin I created above #907 (comment).

@davidnagli @DeMoorJasper, maybe we should re-open this issue and fix this asap. Because lots of new people are starting to use ant-design with parcel and getting a roadblock with less mostly because parcel does not read the less configuration.

It's a parcel issue. I vote to re-open this.

@mischnic
Copy link
Member

I tried the setup in #907 (comment) and it seemed to build successfully.

Could someone post an updated example and what the expected behaviour is?

@ghost
Copy link

ghost commented Jan 6, 2020

Has anyone found a solution I still can't use less ^3?

@konsumer
Copy link

@entrptaher 's solution above, while totally a hack, works awesome for me. This is what I do in a lot of projects, now. I think the asset-loader should probably read the .lessrc, and also maybe just have a default that enables javascriptEnabled. I have this come up with rsuite, ant, and a few others, and it seems to be a reasonable default.

@pojntfx
Copy link

pojntfx commented Apr 18, 2020

So, #4475 fixes the issue! This allows for Antd etc. to be used:

package.json:

{
  "name": "parcel-ant",
  "devDependencies": {
    "@parcel/transformer-less": "^2.0.0-alpha.3",
    "less": "^3.11.1",
    "parcel": "2.0.0-nightly.225"
  },
  "dependencies": {
    "antd": "^4.1.3",
    "react": "^16.13.1",
    "react-dom": "^16.13.1"
  },
  "scripts": {
    "start": "parcel index.html"
  }
}

.lessrc:

{
  "javascriptEnabled": true
}

index.less:

@import "antd/dist/antd.less";
@primary-color: purple;

App.js

import React from "react"
import { DatePicker } from "antd"
import "./index.less"

export default (props) => <DatePicker {...props} />

This is the result:

Screen Shot 2020-04-18 at 09 31 04

Works as expected!

@lemondreamtobe
Copy link

Apperently the LessAsset does not read the .lessrc file at all. I have zero clues at this moment.

However the fix was just one line one file.
image

I extracted the code and published as a npm module till they somehow fix it in future. Steps to follow:

yarn add -D parcel-plugin-less-js-enabled

Before:

➜  experiment-parcel-antd git:(master) ✗ yarn start
yarn run v1.13.0
$ parcel src/index.html
Server running at http://localhost:1234 
🚨  node_modules/antd/lib/form/style/index.less: Inline JavaScript is not enabled. Is it set in your options?

Now:

➜  experiment-parcel-antd git:(master) ✗ yarn start
yarn run v1.13.0
$ parcel src/index.html
Server running at http://localhost:1234 
✨  Built in 343ms.

it really works for me ! big thanks!

@fayismahmood
Copy link

I got works correctly!

my environment:

parcel-bundler: 1.12.3
less: 3.9.0
less-loader: 5.0.0
(antd: 3.19.5)

<project root>/.lessrc

{
  "javascriptEnabled": true
}

NOT "inlineJavaScript"

<project root>/src/index.less

@import "~antd/dist/antd.less";

@primary-color: #4caf50;

Thanks alot

@avalanche1
Copy link

Still getting this error for Parcel 2.
Proposed solution doesn't work.

@vollantre
Copy link

same

Still getting this error for Parcel 2.
Proposed solution doesn't work.

Still getting this error for Parcel 2.
Proposed solution doesn't work.

Same here, please can anyone help

@joshua-hashimoto
Copy link

I still have the same problem too.
In my case it was working just fine like 4 days ago, but after I installed antd icon package it just started throwing errors. samething after uninstalling the package

@xiemeilong
Copy link

This issue is still exist in the latest parcel. I workaround by hard code to the @parcel/transformer-less. The .lessrc file is not readed all the time.

diff --git a/node_modules/@parcel/transformer-less/lib/loadConfig.js b/node_modules/@parcel/transformer-less/lib/loadConfig.js
index eb1f93e..f6f20f7 100644
--- a/node_modules/@parcel/transformer-less/lib/loadConfig.js
+++ b/node_modules/@parcel/transformer-less/lib/loadConfig.js
@@ -36,6 +36,7 @@ async function load({
 
   configContents.rewriteUrls = 'all';
   configContents.plugins = configContents.plugins || []; // This should enforce the config to be reloaded on every run as it's JS
+  configContents.javascriptEnabled = true;
 
   let isDynamic = configFile && _path().default.extname(configFile.filePath) === '.js';

@avalanche1
Copy link

Guess, Antd and Parcel are simply not compatible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests