-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add additional build target of compiled es2015 mode w/ native es2015 module syntax #154
Conversation
Thank you for taking the time to improve ally.js! As far as I can see the I see you've added a |
Yup the The Let me do a little more digging to make sure this works out of the box for webpack 2 and rollup users not just for my specific use case. |
Ok I've done a little more digging around how this treats dependencies. The original issues that I was trying to solve with this PR was when using the Angular 2 AoT compiler the raw ES 2015 source would get pulled into the bundle breaking both minification (Uglify JS) and older browsers that did support some parts of the syntax (like IE 11, ect...). Adding this new build target of compiled ES 2015 code but retaining the ES 2015 module syntax fixed both issues. Inspecting the output of my application with To make sure this worked in a more standard use case (Rollup and webpack 2 with Babel) I made the following app: // modules are in dist because I have this linked locally. Would be ally.js/esm once released
import whenKey from 'ally.js/dist/esm/when/key.js';
import whenVisableArea from 'ally.js/dist/esm/when/visible-area.js';
import maintainHidden from 'ally.js/dist/esm/maintain/hidden.js';
import maintainDisabled from 'ally.js/dist/esm/maintain/disabled.js';
import maintainTabFocus from 'ally.js/dist/esm/maintain/tab-focus.js';
import queryFirstTabbable from 'ally.js/dist/esm/query/first-tabbable.js';
import queryTabbable from 'ally.js/dist/esm/query/tabbable.js';
console.log({
whenKey,
whenVisableArea,
maintainHidden,
maintainDisabled,
maintainTabFocus,
queryFirstTabbable,
queryTabbable
}); and the following Rollup and webpack and configs: import babel from 'rollup-plugin-babel';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
export default {
entry: 'main.js',
dest: 'dist/with-rollup.js',
plugins: [
nodeResolve(), // required to make Rollup understand how to load things from node_modules
commonjs(), // require to make Rollup load some of the CJS deps like platform, ect...
babel({
exclude: 'node_modules/**'
})
]
} var path = require('path');
module.exports = {
entry: './main.js',
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader'
}
]
},
output: {
filename: 'with-webpack.js',
path: path.resolve(__dirname, 'dist')
}
}; Webpack works great out of the box. Rollup builds successfully with the following warning:
This means that Rollup essentially breaks The I tried upgrading to 2.0.0 of |
Nice work!
As far as I can see we should be able to replace that dependency by creating export default function(list, callback) {
const length = list.length;
for (let i = 0; i < length; i++) {
if (callback(list[i])) {
return i;
}
}
return -1;
} I've been waiting for an excuse to remove Do you want to continue working on this? |
Sure! Since you have been looking for an excuse I'll replace |
Let me know if you want me to tweak anything else! |
Looking good! The last tweaks I see:
Do you want take this to the finish line, or should I take over? (sorry for being a bit ridiculous here) |
I would like to take this to the finish line if you are willing to wait until tomorrow for it 😄 . Just to make sure I understand:
This PR should have 2 commits as a result:
|
<3
correct :) |
Ok, I think I have got everything squashed/rebased as you requested. Let me know if you want any more changes. |
Thank you very much for your contribution! I've just released v1.4.1 containing your changes. :) |
I've been using ally.js to handling accessibility in some Angular 2 components I have been making. I did run into a problem though when trying to build my final app with the Angular 2 Ahead-of-Time compiler. One of the compilers limitations is that all modules have to be in the ES 2015 module syntax and ally.js is distributed as UMD. Originally this wasn't a problem becuase ally.js was written in ES 2015 modules so I was able to do:
and everything worked, but since
ally.js
was coming fromnode_modules
it wasn't getting compiled down to ES5 to work in older browsers and Uglify also complained since Uglify JS can't minify most ES 2015 code.While I could have tried to reconfigure by build to also compile the
ally.js
source, it seemed better to add a build ofally.js
that had everything except the ES2015 modules compiled to ES5. Once this gets published to NPM you should be able to do the following in TypeScript, Rollup and webpack 2 with no loaders or plugins:To import the ES2015 modules that have been precompiled for you. This made including ally.js in my Angular 2 app as easy as:
I've also updated the build docs to reflect these change. Let me know if you want me to make any edits there.