Closed vdfor closed 6 years ago
Just moved the description from the seperate comment into the issue body...
lessrc no working
@chenshuai2144 Please open a separate issue
@vdfor We donβt support inline JavaScript yet
I think it should be able to turn on this function in lessrc
less3.0.1 no working,but less2.7.3 is working
Encountered same problem, all you have to do is add --js flag to lessc command: lessc --js foo.less > bar.css
@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.
@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
@schtr4jh Thanks for the quick response! I'll try to downgrade lessc.
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
@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.
Is this fixed? I've been trying to use Antd's babel-plugin-import with Parcel, but doesn't seems to be helpful
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
}]
]
}
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
Having the same problem, have to stay on 2.7.3 for now. Hopefully this will be fixed soon.
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
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.
Solution for webpack example:
loader: 'less-loader',
options: {
javascriptEnabled: true
}
seems .lessrc take no effect
Why issue is closed? The problem still exists
v3 still does not work in 2019. Is using version 2.7.1 really the only work around?
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.
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.
I have fixed this problem just changing "style":true
at .babelrc antd import for "style": "css"
.
.babelrc
{
"plugins": [
"@babel/plugin-proposal-class-properties",
["import", { "libraryName": "antd", "style": true }],
]
}
Print screen
{
"plugins": [
"@babel/plugin-proposal-class-properties",
["import", { "libraryName": "antd", "style": "css" }],
]
}
Print screen
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;
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~
Same here. It works!
Solution for webpack example:
loader: 'less-loader', options: { javascriptEnabled: true }
This solution worked for me
@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;
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 https://github.com/parcel-bundler/parcel/issues/907#issuecomment-494668029.
@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.
I tried the setup in https://github.com/parcel-bundler/parcel/issues/907#issuecomment-511130343 and it seemed to build successfully.
Could someone post an updated example and what the expected behaviour is?
Has anyone found a solution I still can't use less ^3?
@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.
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:
Works as expected!
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.
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!
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
Still getting this error for Parcel 2. Proposed solution doesn't work.
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
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
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';
Guess, Antd and Parcel are simply not compatible.
When using less3, how to enable inline javaScript?