Skip to content

Commit

Permalink
fix: able to require a file inside a module (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
mastilver authored Jul 19, 2017
1 parent 8e1ad62 commit f81c0a5
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"dependencies": {
"babel-runtime": "^6.23.0",
"html-webpack-include-assets-plugin": "0.0.5",
"read-pkg": "^2.0.0",
"read-pkg-up": "^2.0.0",
"resolve-pkg": "^1.0.0"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moduleToCdn from 'module-to-cdn';
import {sync as readPkg} from 'read-pkg';
import {sync as readPkgUp} from 'read-pkg-up';
import HtmlWebpackIncludeAssetsPlugin from 'html-webpack-include-assets-plugin';
import ExternalModule from 'webpack/lib/ExternalModule';
import resolvePkg from 'resolve-pkg';
Expand Down Expand Up @@ -70,7 +70,7 @@ export default class ModulesCdnWebpackPlugin {
return false;
}

const {version, peerDependencies} = readPkg(resolvePkg(modulePath, {cwd: contextPath}));
const {version, peerDependencies} = readPkgUp({cwd: resolvePkg(modulePath, {cwd: contextPath})}).pkg;

const cdnConfig = moduleToCdn(modulePath, version, {env});

Expand Down
27 changes: 27 additions & 0 deletions test/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,30 @@ test.serial('verbose options to output which modules are loaded from CDN / which

console.log = originalLog;
});

test('require files without extension', async t => {
await cleanDir(path.resolve(__dirname, './fixtures/output/require-file'));

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

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

entry: {
app: './require-file.js'
},

plugins: [
new ModulesCdnWebpackPlugin()
]
});

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

t.is(files.length, 1);
t.true(includes(files, 'app.js'));
t.false(includes(files, 'https://unpkg.com/[email protected]/dist/react.js'));
});
1 change: 1 addition & 0 deletions test/fixtures/app/require-file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import React from 'react/react';

0 comments on commit f81c0a5

Please sign in to comment.