Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"presets": [
[
"env",
{
"useBuiltIns": true,
"targets": {
"node": 4.3
},
"exclude": [
"transform-async-to-generator",
"transform-regenerator"
]
}
]
],
"plugins": [
[
"transform-object-rest-spread",
{
"useBuiltIns": true
}
]
],
"env": {
"test": {
"presets": [
"env"
],
"plugins": [
"transform-object-rest-spread"
]
}
}
}
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# editorconfig.org

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[.md]
insert_final_newline = false
trim_trailing_whitespace = false
2 changes: 2 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/dist
6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "webpack",
"rules": {
"no-template-curly-in-string": 0
}
}
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
yarn.lock -diff
* text=auto
bin/* eol=lf
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<!--
1. Check the version of package you are using. If it's not the newest version, update and try again (see changelog while updating!).
2. If the issue is still there, write a minimal project showing the problem and expected output.
3. Link to the project and mention Node version and OS in your report.

**IMPORTANT! You should use [Stack Overflow](https://stackoverflow.com/) for support related questions.**
-->
5 changes: 5 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<!--
1. [Read and sign the CLA](https://cla.js.foundation/webpack/webpack.js.org). This needs to be done only once. PRs that haven't signed it won't be accepted.
2. Check out the [development guide](https://webpack.js.org/development/) for the API and development guidelines.
3. Read through the PR diff carefully as sometimes this can reveal issues. The work will be reviewed, but this can save some effort.
-->
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
node_modules

logs
*.log
npm-debug.log*
yarn-debug.log*
.eslintcache
/coverage
/dist
/local
/reports
/node_modules
.DS_Store
Thumbs.db
.idea
.vscode
*.sublime-project
*.sublime-workspace
32 changes: 32 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
sudo: false
language: node_js
branches:
only:
- master
matrix:
fast_finish: true
include:
- os: linux
node_js: '7'
env: WEBPACK_VERSION="2.2.0" JOB_PART=lint
- os: linux
node_js: '4.3'
env: WEBPACK_VERSION="2.2.0" JOB_PART=test
- os: linux
node_js: '6'
env: WEBPACK_VERSION="2.2.0" JOB_PART=test
- os: linux
node_js: '7'
env: WEBPACK_VERSION="2.2.0" JOB_PART=coverage
before_install:
- nvm --version
- node --version
before_script:
- |-
if [ "$WEBPACK_VERSION" ]; then
yarn add webpack@^$WEBPACK_VERSION
fi
script:
- 'yarn run travis:$JOB_PART'
after_success:
- 'bash <(curl -s https://codecov.io/bash)'
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Change Log

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

x.x.x / <year>-<month>-<day>
==================

* Bug fix -
* Feature -
* Chore -
* Docs -
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Copyright JS Foundation and other contributors

Permission is hereby granted, free of charge, to any person obtaining
Expand Down
67 changes: 0 additions & 67 deletions index.js

This file was deleted.

63 changes: 56 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,66 @@
"version": "0.5.5",
"author": "Tobias Koppers @sokra",
"description": "bundle loader module for webpack",
"main": "dist/cjs.js",
"files": [
"dist"
],
"license": "MIT",
"scripts": {
"webpack-defaults": "webpack-defaults",
"start": "yarn run build -- -w",
"prebuild": "yarn run clean",
"build": "cross-env NODE_ENV=production babel src -d dist --ignore 'src/**/*.test.js'",
"clean": "del-cli dist",
"lint": "eslint --cache src test",
"lint-staged": "lint-staged",
"prepublish": "yarn run build",
"release": "yarn run standard-version",
"security": "nsp check",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"travis:lint": "yarn run lint && yarn run security",
"travis:test": "yarn run test",
"travis:coverage": "yarn run test:coverage"
},
"dependencies": {
"loader-utils": "^1.0.2"
},
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
}
],
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-jest": "^19.0.0",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.4.0",
"cross-env": "^4.0.0",
"del-cli": "^0.2.1",
"eslint": "^3.19.0",
"eslint-config-webpack": "^1.2.2",
"eslint-plugin-import": "^2.2.0",
"jest": "^19.0.2",
"lint-staged": "^3.4.1",
"nsp": "^2.6.3",
"pre-commit": "^1.2.2",
"standard-version": "^4.0.0",
"webpack-defaults": "^0.4.6"
},
"engines": {
"node": ">= 4.3 < 5.0.0 || >= 5.10"
},
"homepage": "https://webpack.js.org",
"repository": {
"type": "git",
"url": "git://github.com/webpack/bundle-loader.git"
"url": "git://github.com/webpack-contrib/bundle-loader.git"
},
"bugs": {
"url": "https://github.com/webpack-contrib/bundle-loader/issues"
},
"pre-commit": "lint-staged",
"lint-staged": {
"*.js": [
"eslint --fix",
"git add"
]
}
}
1 change: 1 addition & 0 deletions src/cjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./index').default;
69 changes: 69 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Tobias Koppers @sokra
*/
import loaderUtils from 'loader-utils';

export function pitch(remainingRequest) { // eslint-disable-line no-unused-vars
const query = loaderUtils.getOptions(this) || {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick 😛 query => options


let chunkNameParam = '';

if (query.name) {
const options = {
context: query.context || this.options.context,
regExp: query.regExp,
};
const chunkName = loaderUtils.interpolateName(this, query.name, options);
chunkNameParam = `, ${JSON.stringify(chunkName)}`;
}

let result;
if (query.lazy) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rename lazy => async, bc of a proposed sync option (#50) and therefore for consistency? And it is semver major anyways :)

Copy link
Member Author

@joshwiens joshwiens May 2, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Lazy references a common naming convention for loading of something.
  • Async is about order of execution or lack there of to be more specific.

Within this particular context i think lazy is the correct name for the query option. Given a bundle is either loader lazy or not I don't see the need to define a sync option given it's the only other practical alternative to lazy and the default if you don't explicitly lazy load the bundle.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If there will never be a sync option, because it doesn't make sense then leaving lazy is better yep :).

result = [
'module.exports = function(cb) {\n',
' require.ensure([], function(require) {\n',
' cb(require(", loaderUtils.stringifyRequest(this, `!!${remainingRequest}`), "));\n',
` }${chunkNameParam});\n`,
'}'];
} else {
result = [
'var cbs = [], \n',
' data;\n',
'module.exports = function(cb) {\n',
' if(cbs) cbs.push(cb);\n',
' else cb(data);\n',
'}\n',
'require.ensure([], function(require) {\n',
' data = require(", loaderUtils.stringifyRequest(this, `!!${remainingRequest}`), ");\n',
' var callbacks = cbs;\n',
' cbs = null;\n',
' for(var i = 0, l = callbacks.length; i < l; i++) {\n',
' callbacks[i](data);\n',
' }\n',
`}${chunkNameParam});`];
}
return result.join('');
Copy link
Member

@michael-ciniawsky michael-ciniawsky Sep 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

join('\n') and remove the \n foreach item? Can be follow up style PR though

}

export default () => { };

/*
Output format:

var cbs = [],
data;
module.exports = function(cb) {
if(cbs) cbs.push(cb);
else cb(data);
}
require.ensure([], function(require) {
data = require("xxx");
var callbacks = cbs;
cbs = null;
for(var i = 0, l = callbacks.length; i < l; i++) {
callbacks[i](data);
}
});

*/
9 changes: 9 additions & 0 deletions test/bundle-loader.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { name as PROJECT_NAME } from '../package.json';
import BundleLoader from '../src';

describe(PROJECT_NAME, () => {
test('should export the loader', (done) => {
expect(BundleLoader).toBeInstanceOf(Function);
done();
});
});
Loading