-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Pre-compiled files? #678
Comments
PS: I just found out about another unofficial package on Bower. For now that will do the trick for me, but the question is the maintainer's future commitment. |
Since recently we maintain a repo of pre-compiled files that is the official source for CDNs: https://github.com/highlightjs/cdn-release. It's updated with each release automatically. Will that work for you? |
Hi Ivan, that looks promising. Is there anything speaking against the addition of a {
"name": "highlight.js",
"version": "8.4.0",
"description": "a syntax highlighter written in JavaScript",
"private": true,
"license": "BSD"
} |
you can try something like that: "devDependencies": {
"highlight.js": "isagalaev/highlight.js"
},
"scripts": {
"postinstall": "cd ./node_modules/highlight.js && npm i && node ./tools/build.js :common"
} |
@grabus Did you try this? I'm getting a issue with permission
|
@idleberg Yes, it works for me. But I use it with grunt like this: grunt.registerTask 'highlight-build', 'highlight-build', ->
exec = require('child_process').exec
cb = @async()
exec 'cd ./bower_components/highlight && npm i && node ./tools/build.js coffeescript css javascript json ruby xml', {}, (err, stdout, stderr) ->
cb()
grunt.registerTask 'build-libs', [
# ...
'lodash:build'
'highlight-build'
# ...
]
You can read here about your issue, there are a couple of solutions. |
Getting back to this… @idleberg yes, I think there's no harm in including a package.json in CDN builds. Could you make a pull request adding that to the build tool? The CDN-related build module is in tools/cdn.js, and may be you could reuse the package.json that we build for npm: https://github.com/isagalaev/highlight.js/blob/master/tools/node.js#L115 |
gulp.task('hjs', function (done) {
var opts = {
cwd: __dirname + '/node_modules/highlight.js'
}
var npmInstall = spawn('npm', ['install'], opts)
npmInstall.stdout.pipe(process.stdout)
npmInstall.stderr.pipe(process.stderr)
npmInstall.on('close', function (code) {
if (0 !== code) throw new Error('npm install exited with ' + code)
var build = spawn('node', ['tools/build.js', '-n', 'json'], opts)
build.stdout.pipe(process.stdout)
build.stderr.pipe(process.stderr)
build.on('close', function (code) {
if (0 !== code) throw new Error('node tools/build.js exited with ' + code)
done()
})
})
}) @idleberg this is what I came up with for https://github.com/kilianc/rtail and it works |
@kilianc Sorry for the late reply. Unfortunately, this does not work for me. What's |
@idleberg |
@kilianc This is great, thanks a lot! |
Yes, thank you! You should think about using that yourself or at least reference it in the Wiki |
@isagalaev, what are you think about separate page in docs to reference all modules/packaging issues? |
I've lost track of this thread, to be honest, but I promise to get back to it as soon as I deal with new-styles in #348. |
@isagalaev
Of course So no providing the build tool in the npm package is forcing to have a bad dependency version management because of the use of git instead of the npm registry. Demo workaroundpackage.json {
"name": "XXX",
"version": "0.0.1",
"private": true,
"devDependencies": {
"gulp": "^4.0.2",
"highlight.js": "git+https://github.com/highlightjs/highlight.js.git#9.16.2"
}
} gulpfile.js // Load plugins
const { series, parallel, src, dest, task } = require('gulp');
const { exec } = require('child_process');
task('build',
parallel(
hljs_style,
series(hljs_build, hljs_webpack)
));
task('build').description = 'Build the static website';
task('default', series('build'));
task('default').description = 'build';
// Copy Highlight.js styles
function hljs_style() {
return src('node_modules/highlight.js/src/styles/*.css')
.pipe(dest('source/css/highlight.js/'));
};
// Build Highlight.js webpack
function hljs_build() {
exec('npm i', {cwd: 'node_modules/highlight.js'});
return exec('node tools/build.js', {cwd: 'node_modules/highlight.js'});
};
// Copy Highlight.js webpack script
function hljs_webpack() {
return src('node_modules/highlight.js/build/highlight.pack.js')
.pipe(dest('source/js/'));
}; |
Related: You might be right, but I'm starting to think the opposite solution is correct. Both the JS distributable and the NPM are "built from source", so we are currently only distributing distributabled assets, with the original source code being on GitHub.
This makes sense to me. The issue seems to be that a lot of people use npm for versioning static assets... so it seems we really need:
That seems to answer what MOST people are asking for I think. With version 10 I was planning on throwing in a pre-built minified "common" build and see if that helps. Nothing will likely change here until post 10.0 anyways (I'd like the next release to be 10.0) since any changes to the build process are most likely going to be built on top of the new build system, not the old one. |
I see some big advantages to keeping NPM as a built deliverable rather than raw source files (which might be a possibility in the future). People using the raw GitHub repo to build with should be uncommon (correct me if you think I'm wrong). Having it as a built asset allows us to make larger behind the scenes changes to how the library is written and structured while still providing the same old "npm API" (same file path locations, mostly same deliverable structure, etc). This ensures stability for those using npm normally, and also allows us to iterate faster with the core library. I'm not sure we want to encourage a lot of people to use the raw source if they don't truly need to... in my experience what people do then is hook into it in custom ways that make their project and ours project more fragile (for new releases). I'm not speaking ill of anyone here (and indeed this is all OSS, so awesome), just pointing out that this often results in more fragility and maintenance time on both sides, increases the likelihood of bugs, etc... We can only really guarantee our external documented API behavior, not the internal code/libs/etc and it's behavior... Also, often many of the things I see being done could be done better with a standardized plugin API (which we're pursuing). Those are my thoughts. IF we shipped a cooked "packed" "binary" with the NPM... what do you see as the big disadvantage to that vs including TWO full copies of the source, cooked and raw...? |
@noraj Is there some reason why the static CDN build doesn't work for you: https://github.com/highlightjs/cdn-release Fetch it once, done. |
Because it's for a project that need to work offline and that need to be self-contained, so I need all the assets locally. |
Why couldn't/wouldn't you just vendor it into a directory of your choice (from the CDN url or from the CDN repo) and then only download the file if it was missing? So after the very first run to build your project would work just fine entirely offline. |
I think what some people want is for
Thoughts? That kind of makes sense to me. What I'm less sure about is merging both into a single large repo. @marcoscaceres Do you have any thoughts on how other npm packages do this? Packages whose client code is DIFFERENT than their server code and who have reasons for using both in various contexts? |
Hmm... I don't know actually. That's a good question, but I don't know what to suggest. |
I was kind of hoping there was some convention everyone else is doing (that makes sense) that we could just point to and follow. :-) I feel like we're unique by having two "targets" (browser and node.js) and that makes us different than a lot of the simpler examples I've seen (so far). |
The only similar ones I can think of is projects that ship with a "-cli"... like babel and babel-cli. So you can get the babel library, and you can get the command line tool separately? |
I see an example: FA. But they have several npm packages in https://www.npmjs.com/~robmadole
Those packages are deprecated and now move into:
By taking a look at https://github.com/FortAwesome/Font-Awesome/blob/master/UPGRADING.md#50x-to-510 you can see they are using something called npm scope More about scope: Also look at their way to store multiple npm packages in one single git repository: https://github.com/FortAwesome/Font-Awesome/tree/master/js-packages/%40fortawesome I hope this could help. Totally different subject: Configuring npm for use with GitHub Packages |
@noraj Interesting, but is that directly comparable? The problem is we have two (at least) entirely different deliverables -- packaged very differently... the browser/CDN build and the node.js build. Currently our npm is the node build. Isn't font awesome really just all client-side resources? IE, it's more like our CDN build... simply publishing the CDN build onto npm under another name was one of the ideas mentioned above. |
Yep. I thought you wanted to make it like that:
One npm package per usage/target. So just add in the git repository a structure like that:
Where So no it's not totally comparable to FA but most of the packaging and delivery idea is here The only difference is that they package logically different stuff and you want to package the "same" stuff for two different targets with some variances. |
Not sure but that's what I'm leaning towards.
I don't think we should add build artifacts to our repository though... I'm not sure what's with that as a trend. I see some advantages but also seems a very annoying thing. We already had the chance to do that with our CDN assets and the original author chose to make a whole separate repo, so I'd say he probably agrees. :-) |
Following up on #678 (comment) If a As an example I forked cdn-release, and created a new branch from tag The {
"name":"@rajsite/highlightjs-cdn-release",
"version": "0.0.1",
"private": true
} Where the name I'm using is under a public scope I own ( Then I was able to add it to a project using:
For what it's worth, I would still prefer a |
What if we pushed the CDN repo to npm ourselves under another name ( |
That would make sense to me. It would be nice if the versions matched and LICENSE + README were included as well (a License file is missing right now from what I can tell). Right now from cdn-release I'm pulling in the min plus a couple of additional languages as separate JS files from cdn git. It's not perfect for code size / number of network requests but helps with getting started and kicking the tires. separate npm package sounds great! 👍 |
You mean in the |
In the
|
Well the actual built package is in Although we could probably add a root license... a simple PR would probably resolve that. ;-) |
This is considered resolved by: https://www.npmjs.com/package/@highlightjs/cdn-assets If you really want your pre-compiled assets from NPM (whether via npm/yarn or https://unpkg.com or something else) vs some other method, the |
Switch to @highlightjs/cdn-release for builds highlightjs/highlight.js#678
Worked great for me! Thanks! :D |
I guess I'm not the only one looking for a way to get a pre-compiled files of hljs. So far, I tried several ways to overcome this, but none of the following was completely satisfying.
Bower
Bower is probably where pre-compiled files would fit best, but the package available is not official and outdated (as you are aware).
npm
The package distributed on npm is made for — and that's fine, I guess, since this is what npm is primarily made for. As I understand it I cannot use the node package to embed it on a website. So, instead I tried to build it using Gulp. Since it's possible to specify any GitHub repository (if it comes with a
package.json
) as a dependency, I tried building hljs using node.Unfortunately, this does not seem to work due to a problem with file permissions (I wonder if including an empty
build
folder would solve this). Next I tried gulp-shell to build directly from gulp, but the tasks aborts due to missing dependencies (of hljs).cdnjs
Ultimately, I ended up using a Gulp task that downloads JS and CSS from cdnjs. It works, but it left me with a somewhat awkward feeling.
Is their another possibility I'm overlooking? Are there any plans to make this easier in the future? I suspect many users would welcome the idea to get pre-compiled files and Bower is maybe the right place for it. Just my two cents.
The text was updated successfully, but these errors were encountered: