-
-
Notifications
You must be signed in to change notification settings - Fork 489
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
Support output.path interpolation #304
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,6 +35,7 @@ class BundleAnalyzerPlugin { | |
|
||
const done = (stats, callback) => { | ||
callback = callback || (() => {}); | ||
const bundleDir = stats.compilation.getPath(stats.compilation.outputOptions.path); | ||
|
||
const actions = []; | ||
|
||
|
@@ -48,9 +49,9 @@ class BundleAnalyzerPlugin { | |
} | ||
|
||
if (this.opts.analyzerMode === 'server') { | ||
actions.push(() => this.startAnalyzerServer(stats.toJson())); | ||
actions.push(() => this.startAnalyzerServer(stats.toJson(), bundleDir)); | ||
} else if (this.opts.analyzerMode === 'static') { | ||
actions.push(() => this.generateStaticReport(stats.toJson())); | ||
actions.push(() => this.generateStaticReport(stats.toJson(), bundleDir)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not a huge fan in how I had to add another argument to these methods to get this working |
||
} | ||
|
||
if (actions.length) { | ||
|
@@ -99,27 +100,27 @@ class BundleAnalyzerPlugin { | |
} | ||
} | ||
|
||
async startAnalyzerServer(stats) { | ||
async startAnalyzerServer(stats, bundleDir) { | ||
if (this.server) { | ||
(await this.server).updateChartData(stats); | ||
} else { | ||
this.server = viewer.startServer(stats, { | ||
openBrowser: this.opts.openAnalyzer, | ||
host: this.opts.analyzerHost, | ||
port: this.opts.analyzerPort, | ||
bundleDir: this.getBundleDirFromCompiler(), | ||
bundleDir: bundleDir || this.getBundleDirFromCompiler(), | ||
logger: this.logger, | ||
defaultSizes: this.opts.defaultSizes, | ||
excludeAssets: this.opts.excludeAssets | ||
}); | ||
} | ||
} | ||
|
||
async generateStaticReport(stats) { | ||
async generateStaticReport(stats, bundleDir) { | ||
await viewer.generateReport(stats, { | ||
openBrowser: this.opts.openAnalyzer, | ||
reportFilename: path.resolve(this.compiler.outputPath, this.opts.reportFilename), | ||
bundleDir: this.getBundleDirFromCompiler(), | ||
reportFilename: path.resolve(bundleDir || this.compiler.outputPath, this.opts.reportFilename), | ||
bundleDir: bundleDir || this.getBundleDirFromCompiler(), | ||
logger: this.logger, | ||
defaultSizes: this.opts.defaultSizes, | ||
excludeAssets: this.opts.excludeAssets | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,21 @@ describe('Plugin', function () { | |
}); | ||
}); | ||
|
||
it('should support webpack config with interpolation in `output.path`', async function () { | ||
const config = makeWebpackConfig(); | ||
config.output.path += '/[hash]'; | ||
|
||
await webpackCompile(config); | ||
|
||
const chartData = await getChartDataFromReport('7e56a1f8a54acedcc9ce/report.html'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this hash is the same across different webpack versions... this might cause a very brittle test. I don't yet have good ideas on how to figure out the hash that was used to get to the report page. |
||
expect(chartData[0]).to.containSubset({ | ||
label: 'bundle.js', | ||
statSize: 141, | ||
parsedSize: 1311, | ||
gzipSize: 342 | ||
}); | ||
}); | ||
|
||
it('should support webpack config with `multi` module', async function () { | ||
const config = makeWebpackConfig(); | ||
|
||
|
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.
I have no idea if this
getPath
function is a public API from webpack. And neither do I know ifstats.compilation.outputOptions.path
is OK to use here.