Skip to content

Commit

Permalink
fix: make sure the module user request is set (#30)
Browse files Browse the repository at this point in the history
* fix: make sure the module user request is set

* test: support webpack@2 require syntax
  • Loading branch information
mastilver committed Aug 24, 2017
1 parent 7b4cac6 commit 2c53826
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class DynamicCdnWebpackPlugin {
return factory(data, cb);
}

cb(null, new ExternalModule(varName));
cb(null, new ExternalModule(varName, 'var', modulePath));
});
});
});
Expand Down
37 changes: 37 additions & 0 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fs from 'mz/fs';

import test from 'ava';
import includes from 'babel-runtime/core-js/string/includes';
import webpack from 'webpack';

import DynamicCdnWebpackPlugin from '../src';

Expand Down Expand Up @@ -572,3 +573,39 @@ test('when resolver retuns a Promise', async t => {
const doesIncludeReact = includes(output, 'THIS IS REACT!');
t.false(doesIncludeReact);
});

test('when used with NamedModulesPlugin', async t => {
await cleanDir(path.resolve(__dirname, './fixtures/output/named-modules'));

const stats = await runWebpack({
context: path.resolve(__dirname, './fixtures/app'),

output: {
publicPath: '',
path: path.resolve(__dirname, './fixtures/output/named-modules')
},

entry: {
app: './single.js'
},

plugins: [
new DynamicCdnWebpackPlugin(),
new webpack.NamedModulesPlugin()
]
});

const files = stats.compilation.chunks.reduce((files, x) => files.concat(x.files), []);

t.is(files.length, 2);
t.true(includes(files, 'app.js'));
t.true(includes(files, 'https://unpkg.com/react@15.6.1/dist/react.js'));

const output = await fs.readFile(path.resolve(__dirname, './fixtures/output/named-modules/app.js'));

const doesHaveIncorrectRequire = includes(output, '__webpack_require__(undefined)');
t.false(doesHaveIncorrectRequire);

const doesHaveCorrectReactRequire = includes(output, '__webpack_require__("react")') || includes(output, '__webpack_require__(0)');
t.true(doesHaveCorrectReactRequire);
});

0 comments on commit 2c53826

Please sign in to comment.