|
4 | 4 | // that your loader plugins (e.g., require('./mystyles.less')) work in exactly the same way on the server as |
5 | 5 | // on the client. |
6 | 6 | import 'es6-promise'; |
| 7 | +import * as path from 'path'; |
7 | 8 | import * as webpack from 'webpack'; |
8 | 9 | import { requireNewCopy } from './RequireNewCopy'; |
9 | 10 |
|
@@ -40,7 +41,15 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string) |
40 | 41 | const webpackConfig: webpack.Configuration = requireNewCopy(webpackConfigPath); |
41 | 42 | webpackConfig.entry = modulePath; |
42 | 43 | webpackConfig.target = 'node'; |
43 | | - webpackConfig.output = { path: '/', filename: 'webpack-output.js', libraryTarget: 'commonjs' }; |
| 44 | + |
| 45 | + // Make sure we preserve the 'path' and 'publicPath' config values if specified, as these |
| 46 | + // can affect the build output (e.g., when using 'file' loader, the publicPath value gets |
| 47 | + // set as a prefix on output paths). |
| 48 | + webpackConfig.output = webpackConfig.output || {}; |
| 49 | + webpackConfig.output.path = webpackConfig.output.path || '/'; |
| 50 | + webpackConfig.output.filename = 'webpack-output.js'; |
| 51 | + webpackConfig.output.libraryTarget = 'commonjs'; |
| 52 | + const outputVirtualPath = path.join(webpackConfig.output.path, webpackConfig.output.filename); |
44 | 53 |
|
45 | 54 | // In Node, we want anything under /node_modules/ to be loaded natively and not bundled into the output |
46 | 55 | // (partly because it's faster, but also because otherwise there'd be different instances of modules |
@@ -85,7 +94,7 @@ function loadViaWebpackNoCache<T>(webpackConfigPath: string, modulePath: string) |
85 | 94 | + stats.toString({ chunks: false })); |
86 | 95 | } |
87 | 96 |
|
88 | | - const fileContent = compiler.outputFileSystem.readFileSync('/webpack-output.js', 'utf8'); |
| 97 | + const fileContent = compiler.outputFileSystem.readFileSync(outputVirtualPath, 'utf8'); |
89 | 98 | const moduleInstance = requireFromString<T>(fileContent); |
90 | 99 | resolve(moduleInstance); |
91 | 100 | } catch(ex) { |
|
0 commit comments