Skip to content
This repository was archived by the owner on May 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
9affe21
Add server-side example
ericclemmons Jan 2, 2016
5dce157
Add CSS for example
ericclemmons Jan 4, 2016
52780fb
Improve server.js example
ericclemmons Jan 4, 2016
72b2694
Rename to npm-install-webpack-plugin
ericclemmons Jan 10, 2016
745c899
First pass at plugin
ericclemmons Jan 10, 2016
a719d17
Update npm run link to use npm-install-webpack-plugin
ericclemmons Jan 10, 2016
c967c25
webpack.config uses NpmInstallPlugin
ericclemmons Jan 10, 2016
17f1fe0
Remove .npmrc to test CLI options
ericclemmons Jan 23, 2016
6c5a20a
Import bootswatch instead of bootstrap
ericclemmons Jan 23, 2016
6e716ae
Complex webpack builds
ericclemmons Jan 23, 2016
5ae4cda
Prettier example
ericclemmons Jan 23, 2016
a66b116
Improve README
ericclemmons Jan 23, 2016
ca151ae
Step-by-step server example
ericclemmons Jan 23, 2016
e126e44
Installer operates on one file at a time
ericclemmons Jan 23, 2016
ec28fb1
Refactor plugin
ericclemmons Jan 23, 2016
31aa631
Update to Node v5.5.0
ericclemmons Jan 23, 2016
a30433f
Loaders are always installed. Sub-modules are not.
ericclemmons Jan 23, 2016
16d713d
Fix strict mode error with "package"
ericclemmons Jan 23, 2016
d19aeb6
Ignore global modules (e.g. "path")
ericclemmons Jan 23, 2016
ff16b20
Add babel + webpack
ericclemmons Jan 23, 2016
0329237
Convert example to ES2016
ericclemmons Jan 23, 2016
31fb1c0
Ignore symlinked modules
ericclemmons Jan 23, 2016
90ada63
Convert example to React
ericclemmons Jan 23, 2016
f0cd856
babel-loader ignores node_modules
ericclemmons Jan 23, 2016
7cd60ef
Default to .npmrc for installs (faster with cache-min!)
ericclemmons Jan 23, 2016
47d79db
Uncomment server
ericclemmons Jan 23, 2016
56d719e
Remove React as a devDependency
ericclemmons Jan 23, 2016
a8cb2d5
React is a dependency
ericclemmons Jan 24, 2016
eed1ba0
Remove parser & test
ericclemmons Jan 24, 2016
d7044c3
Remove loader & test
ericclemmons Jan 24, 2016
e1d0308
plugin + test
ericclemmons Jan 24, 2016
c1d1d0a
Add NPM keyword "webpack-plugin"
ericclemmons Jan 24, 2016
43acb06
Fix example/package.json
ericclemmons Jan 24, 2016
fbfbece
Remove babel-core as a dependency
ericclemmons Jan 24, 2016
9c1352b
Remove loader-utils as a dependency
ericclemmons Jan 24, 2016
34f662d
Update dependencies
ericclemmons Jan 24, 2016
4dfc309
Remove unnecessary console.error
ericclemmons Jan 24, 2016
b14b1c1
Return early for missing dependency
ericclemmons Jan 24, 2016
1924688
Update installer.test for single-dependency installs
ericclemmons Jan 24, 2016
f206cf3
Remove trailing ,
ericclemmons Jan 24, 2016
e299952
Rewrite README for plugin usage
ericclemmons Jan 24, 2016
922eeb6
Update package.json with plugin name, not loader
ericclemmons Jan 24, 2016
b098376
Add support for @namespaced/modules
ericclemmons Jan 24, 2016
ae360a9
Simplify INTERNAL vs. EXTERNAL check
ericclemmons Jan 24, 2016
1948013
Comment on why global module logic works
ericclemmons Jan 24, 2016
343c8e3
Test for non-saved dependencies
ericclemmons Jan 24, 2016
570cd11
Rename this.spy to this.sync for clarity
ericclemmons Jan 24, 2016
f61cb58
Add test for webpack-specific requests
ericclemmons Jan 24, 2016
3865a5f
Fix bug with webpack requests
ericclemmons Jan 24, 2016
d302c39
"missing dependency" is redundant
ericclemmons Jan 24, 2016
ffd0537
index.html can be inlined
ericclemmons Jan 24, 2016
e8396b6
2016
ericclemmons Jan 24, 2016
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
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Eric Clemmons
Copyright (c) 2016 Eric Clemmons

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

81 changes: 36 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
# npm-install-loader
# npm-install-webpack-plugin

> Webpack loader to automatically npm install & save dependencies.
> Webpack plugin that automatically **installs & saves missing dependencies**
> while you work!

Seamless works with:
- [x] Javascript
(e.g. `require`, `import`)
- [x] CSS
(e.g. `@import "~bootstrap"`)
- [x] Webpack loaders
(e.g. `babel-loader`, `file-loader`, etc.)

[![travis build](https://img.shields.io/travis/ericclemmons/npm-install-loader.svg)](https://travis-ci.org/ericclemmons/npm-install-loader)
[![Coverage Status](https://coveralls.io/repos/ericclemmons/npm-install-loader/badge.svg?branch=master&service=github)](https://coveralls.io/github/ericclemmons/npm-install-loader?branch=master)
[![version](https://img.shields.io/npm/v/npm-install-loader.svg)](http://npm.im/npm-install-loader)
[![downloads](https://img.shields.io/npm/dm/npm-install-loader.svg)](http://npm-stat.com/charts.html?package=npm-install-loader)
[![MIT License](https://img.shields.io/npm/l/npm-install-loader.svg)](http://opensource.org/licenses/MIT)
[![travis build](https://img.shields.io/travis/ericclemmons/npm-install-webpack-plugin.svg)](https://travis-ci.org/ericclemmons/npm-install-webpack-plugin)
[![Coverage Status](https://coveralls.io/repos/ericclemmons/npm-install-webpack-plugin/badge.svg?branch=master&service=github)](https://coveralls.io/github/ericclemmons/npm-install-webpack-plugin?branch=master)
[![version](https://img.shields.io/npm/v/npm-install-webpack-plugin.svg)](http://npm.im/npm-install-webpack-plugin)
[![downloads](https://img.shields.io/npm/dm/npm-install-webpack-plugin.svg)](http://npm-stat.com/charts.html?package=npm-install-webpack-plugin)
[![MIT License](https://img.shields.io/npm/l/npm-install-webpack-plugin.svg)](http://opensource.org/licenses/MIT)

- - -

Expand All @@ -18,59 +26,42 @@ build script & server just to install
a dependency you didn't know you needed until now.

Instead, use `require` or `import` how you normally would and `npm install`
will happen automatically install missing dependencies between reloads.
will happen **automatically install & save missing dependencies** while you work!

### Usage

In your `webpack.config.js`:

```js
module: {
postLoaders: [
{
exclude: /node_modules/,
loader: "npm-install-loader",
test: /\.js$/,
},
],
}
plugins: [
new NpmInstallPlugin(),
],
```

This will ensure that any other loaders
(e.g. `eslint-loader`, `babel-loader`, etc.) have completed.

### Saving

This loader simply runs `npm install [modules]`.

I recommend creating an `.npmrc` file
in the root of your project with:
**If you have an `.npmrc` file in your project,
those arguments will be used:**

```ini
```
save=true
save-exact=true
```

This will automatically save any dependencies anytime you run `npm install` (no need to pass `--save`).

**Alternatively**, you can provide CLI arguments that get added directly to `npm install`:
Alternatively, you can provide your own arguments to `npm install`:

```js
postLoaders: [
{
exclude: /node_modules/,
loader: "npm-install-loader",
query: {
cli: {
registry: "..." // --registry='...'
save: true, // --save
saveExact: true, // --save-exact
},
},
test: /\.js$/,
},
plugins: [
new NpmInstallPlugin({
...
cacheMin: 999999 // --cache-min=999999 (prefer NPM cached version)
registry: "..." // --registry="..."
save: true, // --save
saveDev: true, // --save-dev
saveExact: true, // --save-exact
...
}),
],

```

### License

> MIT License 2015 © Eric Clemmons
> MIT License 2016 © Eric Clemmons
8 changes: 8 additions & 0 deletions example/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"presets": ["react", "es2015", "stage-0"],
"env": {
"development": {
"presets": ["react-hmre"]
}
}
}
1 change: 1 addition & 0 deletions example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build
3 changes: 3 additions & 0 deletions example/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
cache-min=9999999
save=true
save-exact=true
1 change: 1 addition & 0 deletions example/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v5.5.0
29 changes: 29 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# `npm-install-webpack-plugin` Example

> This example shows how it's possible to start with a minimal project setup
> and rapidly develop by auto-installing both Javascript & CSS dependencies
> without ever leaving the editor.

## Usage

It's recommended to install the same version of Node this is tested against:

```shell
$ nvm install
$ nvm use
```

Install dependencies required to start working:

```shell
$ npm install
```

Start the server that (that doesn't do anything yet):

```shell
$ npm start
```

Finally, open <http://localhost:3000>, make changes to `server.js`
and watch dependencies get installed as you go!
19 changes: 19 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"private": true,
"devDependencies": {
"babel-preset-es2015": "6.3.13",
"babel-preset-react": "6.3.13",
"babel-preset-react-hmre": "1.0.1",
"babel-preset-stage-0": "6.3.13",
"reload-server-webpack-plugin": "1.0.1",
"webpack": "1.12.11"
},
"scripts": {
"link": "(cd .. && npm link .) && npm link npm-install-webpack-plugin",
"postinstall": "npm run link",
"start": "webpack --config webpack.config.server.babel.js --watch"
},
"dependencies": {
"react": "0.14.6"
}
}
6 changes: 6 additions & 0 deletions example/src/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from "react";
import DOM from "react-dom";

import App from "./components/app";

DOM.render(<App />, document.getElementById("app"));
1 change: 1 addition & 0 deletions example/src/components/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@import "~bootswatch/lumen/bootstrap.css";
36 changes: 36 additions & 0 deletions example/src/components/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from "react";

import "./App.css";

export default class App extends React.Component {
render() {
return (
<div className="container">
<div className="page-header">
<h3>
<code>
npm-install-webpack-plugin
</code>
</h3>
</div>

<div className="jumbotron">
<h1>
It Works!
</h1>

<p>
Webpack has successfully compiled the application JS &amp; CSS.
</p>

<a
className="btn btn-primary btn-lg"
href="https://github.com/ericclemmons/npm-install-webpack-plugin"
>
View on Github
</a>
</div>
</div>
);
}
}
30 changes: 30 additions & 0 deletions example/src/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import express from "express";
import webpack from "webpack";

import client from "../webpack.config.client.babel";

const compiler = webpack(client);

export default express()
.get("/", (req, res) => res.send(`
<!doctype html>
<div id="app">
Waiting on <code>client.js</code> to execute...
</div>

<script src="client.js"></script>
`))
.use(require("webpack-dev-middleware")(compiler, {
noInfo: true,
publicPath: client.output.publicPath,
quiet: false,
}))
.use(require("webpack-hot-middleware")(compiler))
.listen(3000, (err) => {
if (err) {
return console.error(err);
}

console.info("Listening on http://localhost:3000/")
})
;
32 changes: 32 additions & 0 deletions example/webpack.config.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import NpmInstallPlugin from "npm-install-webpack-plugin";
import path from "path";

export const defaults = {
context: process.cwd(),

externals: [],

module: {
loaders: [
{ test: /\.css$/, loader: "style-loader" },
{ test: /\.css$/, loader: "css-loader", query: { localIdentName: "[name]-[local]--[hash:base64:5]" } },
{ test: /\.eot$/, loader: "file-loader" },
{ test: /\.js$/, loader: "babel-loader", query: { cacheDirectory: true }, exclude: /node_modules/ },
{ test: /\.json$/, loader: "json-loader" },
{ test: /\.(png|jpg)$/, loader: "url-loader", query: { limit: 8192 } }, // Inline base64 URLs for <= 8K images
{ test: /\.svg$/, loader: "url-loader", query: { mimetype: "image/svg+xml" } },
{ test: /\.ttf$/, loader: "url-loader", query: { mimetype: "application/octet-stream" } },
{ test: /\.(woff|woff2)$/, loader: "url-loader", query: { mimetype: "application/font-woff" } },
],
},

output: {
chunkFilename: "[id].[hash:5]-[chunkhash:7].js",
devtoolModuleFilenameTemplate: "[absolute-resource-path]",
filename: "[name].js",
},

plugins: [
new NpmInstallPlugin(),
],
};
29 changes: 29 additions & 0 deletions example/webpack.config.client.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import path from "path";
import webpack from "webpack";

import { defaults } from "./webpack.config.babel";

export default {
...defaults,

entry: {
client: [
"webpack-hot-middleware/client?reload=true",
"./src/client.js",
],
},

output: {
...defaults.output,
libaryTarget: "var",
path: path.join(defaults.context, "build/client"),
publicPath: "/",
},

plugins: [
...defaults.plugins,
new webpack.HotModuleReplacementPlugin(),
],

target: "web",
}
31 changes: 31 additions & 0 deletions example/webpack.config.server.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import ReloadServerPlugin from "reload-server-webpack-plugin";
import path from "path";

import { defaults } from "./webpack.config.babel";

export default {
...defaults,

entry: {
server: "./src/server.js",
},

externals: [
...defaults.externals,
// Every non-relative module is external
/^[a-z\-0-9]+$/,
],

output: {
...defaults.output,
libraryTarget: "commonjs2",
path: path.join(defaults.context, "build/server"),
},

plugins: [
...defaults.plugins,
new ReloadServerPlugin({ script: "./build/server/server.js" }),
],

target: "node",
}
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require("./src/loader.js");
module.exports = require("./src/plugin.js");
Loading