I need an es5 package
JulienBourgain opened this issue · 4 comments
I don't know why, but in my project, we can compile your lib on every computer in the openspace (windows or linux) but on our jenkins, the angular cli production build failed on guard.js file.
I have forked your lib to provide an es5 version. It works ! https://www.npmjs.com/package/ts-action-es5
But i don't want to fork your lib :(
Can you provide multiple package compilation (es5 and es2015 and umd) on NPM ?
I don't have access to youtube at works, but an ng-conf video talks about multiple compilation target for libraries if you want some informations.
One core maintener of angular cli demonstrate that multi targets build with => https://github.com/filipesilva/angular-quickstart-lib
And ng-packger can do some of these magic of you => https://www.npmjs.com/package/ng-packagr
Angular-cli v1.6.0 to 1.6.6
Angular 4.4.6
Typescript 2.6.2
Yarn 0.24.2 to 1.3.2
Node 8.9.0
ts-action 3.2.2
and the stacktrace
[ERROR] ERROR in main.2079216f4592de770057.bundle.js from UglifyJs
[ERROR] Unexpected token: operator (>) [/var/lib/jenkins/workspace/SIX-FT-webapp-build-no-master/node_modules/@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader.js??ref--4-0!/var/lib/jenkins/workspace/SIX-FT-webapp-build-no-master/node_modules/ts-action/guard.js:5,0][main.2079216f4592de770057.bundle.js:110682,21]
The change to generate ES5 and ES2015 is a simple tweaking of scripts. However, there is a problem.
The implementation of action
uses the spread parameters syntax with a call to super
and the transpiled ES5 implementation will fail with an error if the project in which it's used targets ES2015.
That is, if the ES5 transpilation of action
is passed an actual ES2015 class
, the implementation explodes with this error:
TypeError: Class constructor cannot be invoked without 'new'
Given that Angular's CLI abstracts the Webpack configuration and that a custom Webpack config is required to consume a package's es2015
entry point, I don't think this can be changed without adversely affecting others. That is, if a project has instructed Angular to target ES2015 (which is possible without ejecting), unless the Angular CLI configuration somehow persuades Webpack to use es2015
for all dependencies, ts-action
will break.
I don't think there is a configuration that will make everyone happy. You might be better off looking into why your CI build behaves so differently.
If you want to play with it - or test it with the Angular CLI - there is a branch here with the change, but I don't intend to merge it. At least not right now. And not without bumping the major version.
This is why the angular package format >=4 need to build an es5 build, an es2015 build and an umd build.
You can provide multiple package entry point in your bundled package.json like :
"main": "./bundles/quickstart-lib.umd.js",
"module": "./quickstart-lib.es5.js",
"es2015": "./quickstart-lib.js",
and angular-cli understands that.
You can see a way to do that with this build file => https://github.com/filipesilva/angular-quickstart-lib/blob/master/build.js
I understand that is the intention, but I would like to confirm that it works before merging it. Regardless, it will still be a major version bump as the package does not have to be used with Angular.
I've tested this and I've published 4.0.0 which includes CommonJS, ES5 and ES2015 files.