-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
How to add alias and externals in encore #200
Comments
I tried .autoProvideVariables({
'window.Routing': 'routing',
}) But babel is creaming at me because it doesn't find the depandancies My previous settings with raw webpack externals settings was working :( |
Ok, so it seems I can play with webpack configuration itself:
Or maybe I missed something in the API ? |
Hi @tristanbes, Currently there is no "helper method" to directly manipulate externals and aliases. We add some aliases for Vue.js and Preact but that's all: webpack-encore/lib/config-generator.js Lines 78 to 90 in bcfbbfd
So if you really need them I guess you're doing it the right way :) Note that you can also use |
Adding aliases and externals seems common enough that I think it makes sense to add mutators to the Encore API. Wdyt @Lyrkan? |
Yep, we should probably implement |
I'm struggling with adding aliases right now, I'd expect config.resolve.alias = {
'App': path.resolve('./app/Resources/src/App')
}; To resolve my |
Hi @ddproxy, First thing to check: are you exporting the right config? // Bad
const config = Encore.getWebpackConfig();
config.resolve.alias = { /* ... */ };
module.exports = Encore.getWebpackConfig();
// Good
const config = Encore.getWebpackConfig();
config.resolve.alias = { /* ... */ };
module.exports = config; Then: is |
Adding a bit more information just in case, but yes I'm exporting the correct configuration object. At this point I'm mucking around the webpack config docs, tweaking different advanced settings (such as config.resolve.alias = {
...config.resolve.alias,
'App': path.resolve('./app/Resources/src/App')
};
if (Encore.isProduction()) {
config.plugins = config.plugins.filter(
plugin => !(plugin instanceof webpack.optimize.UglifyJsPlugin)
);
config.plugins.push(new UglifyJsPlugin());
}
module.exports = config; |
More information! My IE: Using config.resolve.alias['App'] = path.resolve(__dirname, './app/Resources/src/App'); according to the webpack docs (https://webpack.js.org/configuration/resolve/#resolve-alias) is supposed to map the following (shortened list)...
Edit: adding |
Well, uh... This is embarrassing... It'd be nice if I used the right path. My issue is resolved now. |
…yrkan) This PR was merged into the master branch. Discussion ---------- Add Encore.addAliases and Encore.addExternals methods This PR adds two new methods to the API (closes #200): * **`Encore.addAliases`**: Adds the given values to the `resolve.alias` setting of the generated config * **`Encore.addExternals`**: Adds the given values to the `external` setting of the generated config Commits ------- eefe8a4 Add Encore.addAliases and Encore.addExternals methods
Is there a way to install this with flex or composer yet, please? |
Hi @MartinLyne,
If you are talking about an existing Flex install, then you'll have to update it manually using |
If I try to manually use that version number with If I do Edit: sorry it seems I was using incorrect yarn reference (using the composer name without "pack" at the end. |
Hm, I just tried it an it works fine:
Are you behind a proxy or something else that could block yarn? |
Wait.. you didn't have to use -pack suffix? I also updated nodejs, if that is relevant (i was at the bottom of the barrel) So I just removed the symfony/webpack-encore-pack that I added (from a stack overflow answer) and encore + externals still works. So I guess it was nodejs version (I only installed it the other day, strange). Wish I'd used verbose earlier to see what was generating that undefined. |
|
In my case "./" before the path caused the issue. let config = Encore.getWebpackConfig();
config.resolve.alias["~"] = path.resolve(__dirname, 'assets/js');
module.exports = config; And then just like this: import Header from '~/components/Header.vue' More Info here: |
Could be nice to have a doc entry about addAliases and addExternals (#217 ) in the https://symfony.com/doc/current/frontend/encore/advanced-config.html . The actual comment about the feature is quite hidden ! |
Also, keep in mind when you define sth as an external, you have to add it manually. Here is an example with bootstrap: In webpack.config.js
In your main template |
Hello,
Since webpack is obscure to me, I'm giving
encore
a chance but i'm strugling with how to add an alias and externals entriesI tried
ctrl+f
inencore
API but didn't found it :(The text was updated successfully, but these errors were encountered: