-
Notifications
You must be signed in to change notification settings - Fork 12k
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
fix(scripts): allow using same lib inside app #3814
Conversation
Could you add a test that would fail before this change? |
ef0d4af
to
acda842
Compare
@hansl done. |
`)); | ||
`)) | ||
// ensure scripts aren't using script-loader when imported from the app | ||
.then(() => expectFileToMatch('dist/main.bundle.js', 'console.log(\'string-script\');')); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So string-script
will be BOTH in scripts.bundle.js
and main.bundle.js
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but in different ways:
// in scripts.bundle.js
/***/ 600:
/***/ function(module, exports) {
module.exports = "console.log('string-script');\r\n"
// in main.bundle.js
/***/ 614:
/***/ function(module, exports) {
console.log('scriptJsContent');
Script loader modifies the content such that it is a string, which makes it useless for normal imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks to me that the real fix isn't this PR then. Can we get rid of script-loader?
I don't want people having 2 versions of, say, jQuery in their apps... we'll have tons of issues filed with that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
script-loader also causes CSP issues since it uses eval
so removing it would be good in general.
Could the scripts be processed (concat, etc.) beforehand and then added as a webpack asset. or maybe a more extensive plugin or loader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding them as an asset is an interesting idea. Maybe we can make a plugin that does that.
acda842
to
c95bbde
Compare
c95bbde
to
0f0bbc9
Compare
LGTM. |
One side effect of this is that it is no longer possible to reference TypeScript files via |
@filipesilva,the 2141 compare these two:
vs
which one is right? |
@guzuomuse why do you say this is not fixed? is there a scenario in your app where you get failures? |
@filipesilva thanks for replying;
in ".angular-cli.json"
and in app.component.ts
and you can still get console error:
|
@guzuomuse you code does not seem to work outside of the CLI, so I don't think it's a CLI bug. See https://plnkr.co/edit/JHc8GOk5sBcQ6XWsHwJ9?p=preview for a repro of what you're trying to do in a plunker. Click the Most likely you're using the JQuery API incorrectly. |
@filipesilva , i don't think i have used jQuery API in a wrong way.. everything goes well; and further again. if you left the 'script:[]' empty ,just remove the 'transition' function in souce code. that's say, if you include jquery in 'script:[..]', |
Ah so Then it really depends on how that plugin functions unfortunately. The global and local When you add But when you import it via an The local copy does not have that semantic plugin. It's up to the plugin to provide For interop with packages that aren't meant to be used as ES6 modules your best bet is to work with the global scope. That means that you add jquery and all those plugins to the script array, and never import them in your TS code. Then you create a Then when you use it in your code you are using the global one and not a locally imported one. That global one has all the legacy jquery plugins you added. |
a,ha; |
I was trying to solve this by creating a vendor.ts file .. but ... can't get it to work
where should this file be placed ? And how should it be referenced ? If I put it in |
@filipesilva .
". am i right? |
You can't lazily load global scripts with import statements, no. If you want to lazy load them you have to find some other way to do it. |
Your script bundle much like the vendor bundle should rarely change. As a result, it will most likely be cached for the user. |
thank you all kind guys.@filipesilva @clydin . and at last i found another way: in ts file,if some plugin featured es6, |
be aware that while that currently works, it is an unsupported capability and may not work in the future. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
We were loading scripts by adding an include list to the
script-loader
loader rule, forcing that list of files to always be loaded with script loader.But there were cases where you could need to load it both via scripts (because other global scripts needed a lib), and inside your app (or libs your app imported).
This cased the import to return a empty object because it was loaded as a string due to being forced through
script-loader
.With this fix, scripts are forced to be loaded via script loader individually for the scripts entry point instead of globally.
Fix #2141