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

Enable ckeditor5 builds to work with RequireJS #385

Merged
merged 8 commits into from
Mar 27, 2018
Merged

Conversation

const outputBody = `CKEDITOR_TRANSLATIONS.add('${ language }',${ stringifiedTranslations })`;
const outputBody = (
// We need to ensure that the CKEDITOR_TRANSLATIONS variable exist and if it exists, we need to extend it.
'(function(d){' +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we add this bit after the code is minified?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I was thinking about someone that wants to use our builds and targets ES5. Otherwise, we can change it to arrow fn.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used Object.assign later 🤦‍♂️

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced it with an arrow function. But targeting ES5 might be important, and this code won't be transpiled, it should be considered.

@coveralls
Copy link

coveralls commented Mar 20, 2018

Coverage Status

Coverage decreased (-0.3%) to 90.161% when pulling 49302db on t/ckeditor5/914 into 0cd5138 on master.

const outputBody = `CKEDITOR_TRANSLATIONS.add('${ language }',${ stringifiedTranslations })`;
const outputBody = (
// We need to ensure that the CKEDITOR_TRANSLATIONS variable exist and if it exists, we need to extend it.
'(d=>' +
Copy link
Member

@Reinmar Reinmar Mar 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't mean – why it was a function? I meant – why it's minified? I'm completely ok with function if you know that this code won't be transpiled. But I'm less ok with manually minifying the code (which makes it hard to read ;P).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it won't be transpiled later. It's added to the built asset. And we want the minified code in the production mode.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Maybe I'm a little bit wrong here. After changing listening to emit event to listening to optimize-chunk-assets it might be optimized later. I'll check it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. In fact, transpilation is done later, but it breaks sourcemaps. I'll try to work-around this quickly.

@ma2ciek
Copy link
Contributor Author

ma2ciek commented Mar 20, 2018

OK. I've found few interesting things digging more into webpack code.

optimize-chunk-assets - on this hook many plugins try to do some things, that's why I felt before. E.g. Babily minifies output files, webpack.BannerPlugin adds a banner with the license. These plugins mainly look at the compilation chunks and for each chunk in chunks, for each fileName in chunk, they mutate the output for the corresponding file. That has some pros and cons in our case.

If we want to have nice looking code that you've proposed #385 (review), than we will need to minify all assets, including translation assets after adding some minifier. But that will also lead to emitting map files (as have source-map enabled) and adding license banner to each translation file - and I'm not sure if we want it.

@ma2ciek
Copy link
Contributor Author

ma2ciek commented Mar 20, 2018

To make it clear, IMO it's best to provide already minified translations and do not touch compilation chunks as other plugins can modify related files and we actually don't want it.

@Reinmar
Copy link
Member

Reinmar commented Mar 20, 2018

Thanks for clarification. It's fine.

@ma2ciek
Copy link
Contributor Author

ma2ciek commented Mar 20, 2018

I've tested it with targeting one language and multiple language and sourcemaps should work fine now. I've updated builds on the t/ckeditor5/914 branches.

@Reinmar
Copy link
Member

Reinmar commented Mar 26, 2018

R- for reasons explained in ckeditor/ckeditor5#914 (comment)

@Reinmar
Copy link
Member

Reinmar commented Mar 27, 2018

I'll finish this PR. Reassigning.

`d['${ language }']||{},` +
`${ stringifiedTranslations }` +
')' +
'})(window.CKEDITOR_TRANSLATIONS||(window.CKEDITOR_TRANSLATIONS={}));'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this kind of access to the global object (through window) is going to hurt in some odd envs, but let's keep it for now.

// We need to ensure that the CKEDITOR_TRANSLATIONS variable exists and if it exists, we need to extend it.
// Use ES5 because this bit will not be transpiled!
'(function(d){' +
`d['${ language }']=Object.assign(` +
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still an ES6 code. We can change it to for in loop to be fully ES5 compatible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object.assign() needs to be provided by a polyfill for the rest of the code anyway. This doesn't get transpiled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be tricky for someone, as we add that code at the top of the bundle.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now we don't support any non-ES6 env anyway, so it's even hard to test. Let's keep it in our minds. But I don't see a problem in injecting the ES6 polyfill before our scripts.

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

Successfully merging this pull request may close these issues.

3 participants