Skip to content

Commit

Permalink
use entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
mastilver committed Jul 3, 2017
1 parent 4b47e53 commit b31346f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
15 changes: 3 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export default class ModulesCdnWebpackPlugin {
}

execute(compiler, {env}) {
compiler.plugin('normal-module-factory', nmf => {
nmf.plugin('factory', factory => (data, cb) => {
compiler.plugin('compile', params => {
params.normalModuleFactory.plugin('factory', factory => (data, cb) => {
const modulePath = data.dependencies[0].request;
const contextPath = data.context;

Expand All @@ -61,15 +61,6 @@ export default class ModulesCdnWebpackPlugin {

cb(null, new ExternalModule(varName));
});

nmf.plugin('parser', (parser, parserOptions) => {
parser.plugin('import-call', expr => {
const modulePath = parser.evaluateExpression(expr.arguments[0]).string;

const dep = new ExternalModule(modulePath, expr.range);
parser.state.current.addDependency(dep);
});
});
});
}

Expand Down Expand Up @@ -117,7 +108,7 @@ export default class ModulesCdnWebpackPlugin {
const url = this.urls[name];

const chunk = compilation.addChunk(name);
chunk.files.push(url);
chunk.entrypoints.push(url);

chunk.parents = [parentChunk];
parentChunk.addChunk(chunk);
Expand Down
12 changes: 5 additions & 7 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -306,22 +306,20 @@ test('async loading', async t => {
},

plugins: [
new ModulesCdnWebpackPlugin({
exclude: ['react']
})
new ModulesCdnWebpackPlugin()
]
});

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

// console.log(stats.compilation.chunks);

t.true(includes(files, 'app.js'));
t.false(includes(files, 'https://unpkg.com/[email protected]/dist/react.js'));

const output = await fs.readFile(path.resolve(__dirname, './fixtures/output/async/app.js'));
const outputs = await Promise.all(files.map(async file => {
return fs.readFile(path.resolve(__dirname, `./fixtures/output/async/${file}`));
}));

// NOTE: not inside t.false to prevent ava to display whole file in console
const doesIncludeReact = includes(output, 'THIS IS REACT!');
const doesIncludeReact = outputs.some(output => includes(output, 'THIS IS REACT!'));
t.false(doesIncludeReact);
});

0 comments on commit b31346f

Please sign in to comment.