Skip to content

Commit

Permalink
Fix scope hoisting (#152)
Browse files Browse the repository at this point in the history
Issues: #151 facebook/create-react-app#4492

Same as 
#117
with a test case.

-----
fix #151 
closes #117
  • Loading branch information
Jack Zhao authored and mastilver committed May 22, 2018
1 parent 95d94ef commit 5dca486
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ ManifestPlugin.prototype.apply = function(compiler) {
var outputName = path.relative(outputFolder, outputFile);

var moduleAsset = function (module, file) {
moduleAssets[file] = path.join(
path.dirname(file),
path.basename(module.userRequest)
);
if (module.userRequest) {
moduleAssets[file] = path.join(
path.dirname(file),
path.basename(module.userRequest)
);
}
};

var emit = function(compilation, compileCallback) {
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"file-loader": "^1.1.11",
"jest": "^22.4.3",
"memory-fs": "^0.2.0",
"react": "^16.3.2",
"rimraf": "^2.6.1",
"style-loader": "^0.8.3",
"svgr": "^1.9.2",
"webpack": "^3.5.2"
},
"files": [
Expand Down
45 changes: 45 additions & 0 deletions spec/plugin.integration.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,48 @@ describe('ManifestPlugin with memory-fs', function() {
});
});
});

describe('scoped hoisting', function() {
beforeAll(function () {
fse.outputFileSync(path.join(__dirname, 'output/scoped-hoisting/index.js'), 'import { ReactComponent } from "./logo.svg";');
fse.outputFileSync(path.join(__dirname, 'output/scoped-hoisting/logo.svg'), '<svg />');
});

it('outputs a manifest', function(done) {
let plugins;
if (webpack.optimize.ModuleConcatenationPlugin) {
// ModuleConcatenationPlugin works with webpack 3, 4.
plugins = [
new webpack.optimize.ModuleConcatenationPlugin(),
new ManifestPlugin(),
];
} else {
plugins = [
new ManifestPlugin(),
];
}
compiler = webpackCompile({
context: __dirname,
entry: './output/scoped-hoisting/index.js',
module: {
rules: [
{
test: /\.svg$/,
use: ['svgr/webpack', 'file-loader']
},
],
},
output: {
filename: '[name].[hash].js',
path: path.join(__dirname, 'output/scoped-hoisting')
},
plugins,
}, {}, function(stats) {
var manifest = JSON.parse(fse.readFileSync(path.join(__dirname, 'output/scoped-hoisting/manifest.json')))

expect(manifest).toBeDefined();
expect(manifest['main.js']).toEqual('main.'+ stats.hash +'.js');
return done();
});
});
});

0 comments on commit 5dca486

Please sign in to comment.