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

Fix new ts-loader rule being added when getWebpackConfig is called #181

Merged
merged 1 commit into from
Oct 14, 2017

Conversation

Lyrkan
Copy link
Collaborator

@Lyrkan Lyrkan commented Oct 13, 2017

Due to the following lines a new ts-loader rule is currently being added everytime the Webpack config is generated (for instance by calling Encore.getWebpackConfig()):

this.webpackConfig.addLoader({
test: /\.tsx?$/,
exclude: /node_modules/,
use: tsLoaderUtil.getLoaders(this.webpackConfig)
});

Example:

// webpack.config.js
const Encore = require('@symfony/webpack-encore');

Encore
    .setOutputPath('build')
    .setPublicPath('/')
    .addEntry('src/index.ts')
    .enableTypeScriptLoader()
;

console.log(Encore.getWebpackConfig().module.rules.length); // => 5
console.log(Encore.getWebpackConfig().module.rules.length); // => 6
console.log(Encore.getWebpackConfig().module.rules.length); // => 7

@Lyrkan Lyrkan added the Bug Bug Fix label Oct 13, 2017
@weaverryan
Copy link
Member

Wow, nice catch. Thanks @Lyrkan!

@weaverryan weaverryan merged commit a2515b4 into symfony:master Oct 14, 2017
weaverryan added a commit that referenced this pull request Oct 14, 2017
…called (Lyrkan)

This PR was merged into the master branch.

Discussion
----------

Fix new ts-loader rule being added when getWebpackConfig is called

Due to the following lines a new ts-loader rule is currently being added everytime the Webpack config is generated (for instance by calling `Encore.getWebpackConfig()`):

https://github.com/symfony/webpack-encore/blob/c6057af7521594d9d76cfd072b1f2421591e4a3f/lib/config-generator.js#L196-L200

__Example:__

```js
// webpack.config.js
const Encore = require('@symfony/webpack-encore');

Encore
    .setOutputPath('build')
    .setPublicPath('/')
    .addEntry('src/index.ts')
    .enableTypeScriptLoader()
;

console.log(Encore.getWebpackConfig().module.rules.length); // => 5
console.log(Encore.getWebpackConfig().module.rules.length); // => 6
console.log(Encore.getWebpackConfig().module.rules.length); // => 7
```

Commits
-------

a2515b4 Fix ts-loader being added everytime getWebpackConfig is called
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug Fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants