Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

refactor: apply webpack defaults #51

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
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"
Copy link
Member

Choose a reason for hiding this comment

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

4.8

},
"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
}
}
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
yarn.lock -diff
* text=auto
bin/* eol=lf
package-lock.json -diff
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
48 changes: 48 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
sudo: false
dist: trusty
language: node_js
branches:
only:
- master
jobs:
fast_finish: true
allow_failures:
- env: WEBPACK_VERSION=canary
include:
- &test-latest
stage: Webpack latest
node_js: 6
env: WEBPACK_VERSION=latest JOB_PART=test
script: npm run travis:$JOB_PART
- <<: *test-latest
node_js: 4.8
env: WEBPACK_VERSION=latest JOB_PART=test
script: npm run travis:$JOB_PART
- <<: *test-latest
node_js: 8
env: WEBPACK_VERSION=latest JOB_PART=lint
script: npm run travis:$JOB_PART
- <<: *test-latest
node_js: 8
env: WEBPACK_VERSION=latest JOB_PART=coverage
script: npm run travis:$JOB_PART
after_success: 'bash <(curl -s https://codecov.io/bash)'
- stage: Webpack canary
before_script: npm i --no-save git://github.com/webpack/webpack.git#master
script: npm run travis:$JOB_PART
node_js: 8
env: WEBPACK_VERSION=canary JOB_PART=test
before_install:
- 'if [[ `npm -v` != 5* ]]; then npm i -g npm@^5.0.0; fi'
- nvm --version
- node --version
- npm --version
before_script:
- |-
if [ "$WEBPACK_VERSION" ]; then
npm i --no-save webpack@$WEBPACK_VERSION
fi
script:
- 'npm 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
68 changes: 46 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
[![npm][npm]][npm-url]
[![node][node]][node-url]
[![deps][deps]][deps-url]
[![test][test]][test-url]
[![coverage][cover]][cover-url]
[![chat][chat]][chat-url]

<div align="center">
@@ -32,7 +35,7 @@ waitForChunk(function(file) {
});
// wraps the require in a require.ensure block

// Multiple callbacks can be added. They will be executed in the order of addition.
// Multiple callbacks can be added. They will be executed in the order of addition.
waitForChunk(callbackTwo);
waitForChunk(callbackThree);
// If a callback is added after dependencies were loaded, it will be called immediately.
@@ -50,12 +53,12 @@ load(function(file) {
```
### `name` query parameter

You may set name for a bundle using the `name` query parameter.
You may set name for a bundle using the `name` query parameter.
See [documentation](https://github.com/webpack/loader-utils#interpolatename).

**Note** chunks created by the loader will be named according to the
**Note** chunks created by the loader will be named according to the
[`output.chunkFilename`](https://webpack.js.org/configuration/output/#output-chunkfilename) rule, which defaults to `[id].[name]`.
Here `[name]` corresponds to the chunk name set in the `name` query parameter.
Here `[name]` corresponds to the chunk name set in the `name` query parameter.

#### Example:

@@ -75,50 +78,71 @@ module.exports = {
}
```

Normal chunks will show up using the `filename` rule above, and be named according to their chunkname.
Normal chunks will show up using the `filename` rule above, and be named according to their chunkname.
Chunks from `bundle-loader`, however will load using the `chunkFilename` rule, so the example files will produce `my-chunk-1.js` and `file-2.js` respectively.

You can also use `chunkFilename` to add hash values to the filename, since putting `[hash]` in the bundle query parameter does not work correctly.
You can also use `chunkFilename` to add hash values to the filename, since putting `[hash]` in the bundle query parameter does not work correctly.

<h2 align="center">Maintainers</h2>

<table>
<tbody>
<tr>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/166921?v=3&s=150">
</br>
<a href="https://github.com/bebraw">Juho Vepsäläinen</a>
<a href="https://github.com/bebraw">
<img width="150" height="150" src="https://github.com/bebraw.png?v=3&s=150">
</br>
Juho Vepsäläinen
</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars2.githubusercontent.com/u/8420490?v=3&s=150">
</br>
<a href="https://github.com/d3viant0ne">Joshua Wiens</a>
<a href="https://github.com/d3viant0ne">
<img width="150" height="150" src="https://github.com/d3viant0ne.png?v=3&s=150">
</br>
Joshua Wiens
</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/533616?v=3&s=150">
</br>
<a href="https://github.com/SpaceK33z">Kees Kluskens</a>
<a href="https://github.com/sapegin">
<img width="150" height="150" src="https://github.com/sapegin.png?v=3&s=150">
</br>
Artem Sapegin
</a>
</td>
<td align="center">
<img width="150" height="150"
src="https://avatars3.githubusercontent.com/u/3408176?v=3&s=150">
</br>
<a href="https://github.com/TheLarkInn">Sean Larkin</a>
<a href="https://github.com/michael-ciniawsky">
<img width="150" height="150" src="https://github.com/michael-ciniawsky.png?v=3&s=150">
</br>
Michael Ciniawsky
</a>
</td>
<td align="center">
<a href="https://github.com/evilebottnawi">
<img width="150" height="150" src="https://github.com/evilebottnawi.png?v=3&s=150">
</br>
Alexander Krasnoyarov
</a>
</td>
</tr>
<tbody>
</table>



[npm]: https://img.shields.io/npm/v/bundle-loader.svg
[npm-url]: https://npmjs.com/package/bundle-loader

[node]: https://img.shields.io/node/v/bundle-loader.svg
[node-url]: https://nodejs.org

[deps]: https://david-dm.org/webpack-contrib/bundle-loader.svg
[deps-url]: https://david-dm.org/webpack-contrib/bundle-loader

[chat]: https://img.shields.io/badge/gitter-webpack%2Fwebpack-brightgreen.svg
[chat-url]: https://gitter.im/webpack/webpack

[test]: http://img.shields.io/travis/webpack-contrib/bundle-loader.svg
[test-url]: https://travis-ci.org/webpack-contrib/bundle-loader

[cover]: https://codecov.io/gh/webpack-contrib/bundle-loader/branch/master/graph/badge.svg
[cover-url]: https://codecov.io/gh/webpack-contrib/bundle-loader
29 changes: 29 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
branches:
only:
- master
init:
- git config --global core.autocrlf input
environment:
matrix:
- nodejs_version: '8'
webpack_version: latest
job_part: test
- nodejs_version: '6'
webpack_version: latest
job_part: test
- nodejs_version: '4.8'
webpack_version: latest
job_part: test
build: 'off'
matrix:
fast_finish: true
install:
- ps: Install-Product node $env:nodejs_version x64
- npm i -g npm@latest
- npm install
before_test:
- cmd: npm install webpack@%webpack_version%
test_script:
- node --version
- npm --version
- cmd: npm run appveyor:%job_part%
67 changes: 0 additions & 67 deletions index.js

This file was deleted.

7,408 changes: 7,408 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

70 changes: 62 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -3,17 +3,71 @@
"version": "0.5.5",
"author": "Tobias Koppers @sokra",
"description": "bundle loader module for webpack",
"main": "dist/cjs.js",
"files": [
"dist"
],
"license": "MIT",
"scripts": {
"start": "npm run build -- -w",
"appveyor:test": "npm run test",
"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",
"prebuild": "npm run clean",
"prepublish": "npm run build",
"release": "standard-version",
"security": "nsp check",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "jest --collectCoverageFrom='src/**/*.js' --coverage",
"travis:lint": "npm run lint && npm run security",
"travis:test": "npm run test -- --runInBand",
"travis:coverage": "npm run test:coverage -- --runInBand",
"webpack-defaults": "webpack-defaults"
},
"dependencies": {
"loader-utils": "^1.0.2"
"loader-utils": "^1.1.0"
},
"licenses": [
{
"type": "MIT",
"url": "http://www.opensource.org/licenses/mit-license.php"
}
],
"devDependencies": {
"babel-cli": "^6.24.1",
"babel-jest": "^20.0.3",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.5.2",
"cross-env": "^5.0.0",
"del-cli": "^1.0.0",
"eslint": "^3.19.0",
"eslint-config-webpack": "^1.2.2",
"eslint-plugin-import": "^2.3.0",
"jest": "^20.0.4",
"lint-staged": "^3.4.1",
"nsp": "^2.6.3",
"pre-commit": "^1.2.2",
"standard-version": "^4.0.0",
"webpack": "^3.6.0",
"webpack-defaults": "^1.6.0"
},
"peerDependencies": {
"webpack": "^2.0.0 || ^3.0.0"
},
"engines": {
"node": ">= 4.8 < 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 options = loaderUtils.getOptions(this) || {};

let chunkNameParam = '';

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

let result;
if (options.lazy) {
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();
});
});