Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack-CLI version 1 #105

Merged
merged 101 commits into from
May 7, 2017
Merged
Show file tree
Hide file tree
Changes from 84 commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
fa41989
feat: initial commit on last structure and transforms
evenstensberg Apr 7, 2017
4cc5d94
feat: ast for entry
evenstensberg Apr 7, 2017
ad3164e
feat: ast for output
evenstensberg Apr 7, 2017
9ce2873
feat: ast for context
evenstensberg Apr 7, 2017
c053082
feat: work in progress on resolve
evenstensberg Apr 8, 2017
9635c96
feat: add transform structure for all
evenstensberg Apr 8, 2017
f92af9c
fix: remove rx from the project
evenstensberg Apr 8, 2017
9977025
fix: return ast on no prop at resolve
evenstensberg Apr 8, 2017
2c6d1de
feat: ast for resolve
evenstensberg Apr 8, 2017
00e1eca
feat: ast for devtool
evenstensberg Apr 9, 2017
7f8da31
feat: art for target
evenstensberg Apr 9, 2017
22df329
feat: ast for watch
evenstensberg Apr 9, 2017
743f10f
feat: sat for watchOptions
evenstensberg Apr 9, 2017
423b8cb
fix: rename dev-tool to devtool
evenstensberg Apr 9, 2017
2f7a10c
feat: ast for externals
evenstensberg Apr 9, 2017
a2b9807
feat: ast for node
evenstensberg Apr 9, 2017
9d5ebbe
feat: sat for performance
evenstensberg Apr 9, 2017
97c627d
feat: ast for stats
evenstensberg Apr 9, 2017
29d0c56
feat: ast for other
evenstensberg Apr 9, 2017
bc6e1de
feat: allow multiple packages in CLI command
evenstensberg Apr 9, 2017
8153f2b
feat: allow dynamic entry points
evenstensberg Apr 10, 2017
3c7b021
feat: allow promises as entry points
evenstensberg Apr 10, 2017
e3d522b
feat: function decl for resolve.cachePredictate
evenstensberg Apr 10, 2017
2f1e891
feat: allow function for performance.assetFilter
evenstensberg Apr 10, 2017
9a230b8
feat: allow regex and functions in external prop
evenstensberg Apr 10, 2017
f87aa2b
feat: regexp for outputPrefix
evenstensberg Apr 10, 2017
009c0e7
feat: use property without strings
evenstensberg Apr 10, 2017
471fa26
feat: allow regex for unsafeCache
evenstensberg Apr 10, 2017
04add9b
feat: ast for module
evenstensberg Apr 10, 2017
bf6a27a
feat: ast for plugins
evenstensberg Apr 11, 2017
3f9d953
feat: art for paths
evenstensberg Apr 11, 2017
026ee74
feat: prettier, topScope and runtime flow
evenstensberg Apr 11, 2017
beda4db
feat: ast for cache
evenstensberg Apr 11, 2017
ea39812
feat: module regexp fix
evenstensberg Apr 11, 2017
02c9b14
feat: fix generator methods
evenstensberg Apr 11, 2017
290e4f2
chore: bump add ons dep
evenstensberg Apr 11, 2017
aba04dd
feat: introduce scaffold for external runs
evenstensberg Apr 11, 2017
6c59cda
feat: don't use jscodeshift to parse unknown values
evenstensberg Apr 12, 2017
d586952
feat: allow name conventions
evenstensberg Apr 12, 2017
559af8c
feat: allow multiple config creations
evenstensberg Apr 12, 2017
89e0376
feat: allow using inject for resolve and module
evenstensberg Apr 13, 2017
ba01b69
feat: allow merge in scaffold
evenstensberg Apr 13, 2017
a024476
fix: make build more readable
evenstensberg Apr 13, 2017
b435585
feat: add HOC to each transform
evenstensberg Apr 14, 2017
7e1ea07
feat: find correct folder for packages
evenstensberg Apr 14, 2017
4dbc02a
fix: example transform in generator and fix to path
evenstensberg Apr 14, 2017
e315511
Add your first test (#114)
Apr 16, 2017
4716da5
Tests for entry.js (#115)
Apr 17, 2017
1567dae
fix: add identifier creation and fix entry tests
evenstensberg Apr 17, 2017
c052bc8
Add more tests (#116)
Apr 18, 2017
b88e3df
Cleanup the ast branch transformation (#117)
Apr 18, 2017
889400c
feat: add new tests for entry & regex for validateOptions
evenstensberg Apr 18, 2017
a958486
feat: more tests for obj ref
evenstensberg Apr 18, 2017
69725c8
fix: fix devtool property and add tests for it
evenstensberg Apr 18, 2017
8f8bd7d
add externals test and fix identifier util
evenstensberg Apr 18, 2017
7ca1948
feat: add test to array with obj reference in ext
evenstensberg Apr 18, 2017
e455a33
fix: fix silly mistake on devtools props
evenstensberg Apr 20, 2017
583520e
tests: add tests for every transform
evenstensberg Apr 20, 2017
efb80ea
feat: add more utility for tests
evenstensberg Apr 20, 2017
6d15a77
enhancements: use abstractions & utils
evenstensberg Apr 22, 2017
107d37c
utils: add regex util
evenstensberg Apr 22, 2017
b7a9226
chore: add JSdocs to each transform
evenstensberg Apr 22, 2017
9859b03
enhancements: use more utility on transforms
evenstensberg Apr 22, 2017
28fc6f0
enhancements: use createpushval for all transforms
evenstensberg Apr 22, 2017
115a73a
enhancements: use new utility to create single properties
evenstensberg Apr 23, 2017
f3ad8af
enhancements: add test for utility functions
evenstensberg Apr 23, 2017
c563328
fix: don't use await for promise
evenstensberg Apr 23, 2017
44ce0d6
enhancements: send each transform object to respective transform
evenstensberg Apr 23, 2017
08bb8e5
enhancements: remove createsingular
evenstensberg Apr 23, 2017
b458b9e
enhancements: use more utility and remove boilerplate code
evenstensberg Apr 23, 2017
fda1003
chore: remove fixme flag
evenstensberg Apr 23, 2017
f2aabaa
chore: prettify ast.find
evenstensberg Apr 23, 2017
ee87141
enhancements: use objKey util for entry and externals
evenstensberg Apr 24, 2017
84b8127
enhancements: use utility on resolve
evenstensberg Apr 24, 2017
74b821a
enhancements: fix merge & utilize module folder
evenstensberg Apr 26, 2017
b34e93e
enhancements: use prettier node API
evenstensberg Apr 30, 2017
635f2db
fix: don't print success msg more than one time
evenstensberg Apr 30, 2017
b32e7a2
enhancements: fix windows paths
evenstensberg Apr 30, 2017
b6c0926
Webpack-CLI Documentation (#112)
evenstensberg Apr 30, 2017
cdd5fb4
chore: prepare to update webpack/bin to ours
evenstensberg Apr 30, 2017
cd5562c
chore: refactor against webpack/lib
evenstensberg Apr 30, 2017
63c30ca
remove shebang
evenstensberg Apr 30, 2017
bde984f
chore: remove old rx code
evenstensberg Apr 30, 2017
042fc7c
enhancements: default generator and exitCode
evenstensberg May 1, 2017
f33f521
chore: update addons pkg and reformat extractAnswer
evenstensberg May 2, 2017
d1342ed
enhancements: better bin resolves & default generator
evenstensberg May 4, 2017
21e7858
enhancements: use validation to force answers
evenstensberg May 4, 2017
0344e6a
enhancements: check identifiers with properties
evenstensberg May 4, 2017
663133a
enhancements: revise anti pattern for promise
evenstensberg May 4, 2017
907a1f7
enhancements: rename write to type and split params to newline
evenstensberg May 5, 2017
c58f793
enhancements: add better scaffold to generator
evenstensberg May 5, 2017
3e6115a
enhancements: make default generator more User Friendly
evenstensberg May 5, 2017
0ba9d7d
enhancements: ask if user wants to make the config at end
evenstensberg May 6, 2017
c6bd40c
enhancements: make default generator better
evenstensberg May 7, 2017
a9ea433
enhancements: add styling option to generator
evenstensberg May 7, 2017
bc24b9e
fix: remove sourceMap from postcss prop
evenstensberg May 7, 2017
f4add5a
enhancements: separate dev and prod build
evenstensberg May 7, 2017
c766779
enhancements: add contentHash & name
evenstensberg May 7, 2017
ef05928
enhancements: prompt for better answers
evenstensberg May 7, 2017
2e2a38f
fix: remove unused module
evenstensberg May 7, 2017
dd9b894
chore: final fixes before release
evenstensberg May 7, 2017
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
1 change: 1 addition & 0 deletions MIGRATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,22 @@

# Webpack CLI

This project intends to be the main cli package of webpack. Here we will encapsulate all the features and code related to the command line. From sending options to the compiler, to initialize and migrate from version to version.
Webpack CLI encapsulates all code related to CLI handling. It captures options and sends them to webpack compiler. You can also find functionality for initializing a project and migrating between versions. For the time being, it is backwards-compatible with the CLI included in webpack itself.

**Note** The package is still in work in progress. In case you want to contribute, reach to us, so we can point you out how and when you can help us.

## Migration from webpack v1 to v2

# Roadmap to the first release
The `migrate` feature eases the transition from [version 1](http://webpack.github.io/docs/) to [version 2](https://gist.github.com/sokra/27b24881210b56bbaff7). `migrate` also allows users to switch to the new version of webpack without having to extensively [refactor](https://webpack.js.org/guides/migrating/).

- Migrate to webpack-cli all the current cli options available in webpack
- Create a `webpack-cli init` command that serves to set a configuration of webpack to the user
- create a `webpack-cli migrate` command that serves to migrate an existing configuration from webpack 1 to webpack 2.
`webpack --migrate <config>`

[Read more about migrating](MIGRATE.md)

## Creating new webpack projects

The `init` feature allows users to get started with webpack, fast. Through scaffolding, people can create their own configuration in order to faster initialize new projects for various of use cases.

`webpack --init [webpack-addons-<package>]`

[Read more about scaffolding](SCAFFOLDING.md)
83 changes: 83 additions & 0 deletions SCAFFOLDING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Introduction

Setting up webpack for the first time is hard. Writing advanced configurations to optimize performance is even harder. The `init` feature is designed to support people that want to create their own configuration or initializing other projects people create.

Through [yeoman](http://yeoman.io/), the `webpack --init` feature allows people to create scaffolds and generate new projects quickly. An npm dependency that scaffolds a `webpack.config.js` through `webpack-cli` is what we refer to as an **addon**.

## Writing a good scaffold

Before writing a `webpack-cli` scaffold, think about what you're trying to achieve. Do you want a "general" scaffold that could be used by any project or type of app? Do you want something very focused - like a scaffold that writes both your `webpack.config.js` and your framework code? It's also useful to think about the user experience for your scaffold.

`webpack-cli` offers an experience that is interactive and you can prompt users for questions (like, "What is your entry point?") to help customize the output accordingly.

## webpack-addons

[`webpack-addons`](https://github.com/webpack-contrib/webpack-addons) is a utility suite for creating addons. It contains functions that could be of use for creating an addon yourself.

## webpack-addons-yourpackage

In order for `webpack-cli` to compile your package, it relies on a prefix of `webpack-addons`. The package must also be published on npm. If you are curious about how you can create your very own `addon`, please read [How do I compose a webpack-addon?](https://github.com/ev1stensberg/webpack-addons-demo).

## API

To create an `addon`, you must create a [`yeoman-generator`](http://yeoman.io/authoring/). Because of that, you can optionally extend your generator to include methods from the [Yeoman API](http://yeoman.io/learning/). Its worth noting that we support all the properties of a regular webpack configuration. In order for us to do this, there's a thing you need to remember.

Objects are made using strings, while strings are made using double strings. This means that in order for you to create an string, you have to wrap it inside another string for us to validate it correctly.


### `opts.env.configuration`(Required)

Initialized inside the constructor of your generator in order for the CLI to work.

```js
constructor(args, opts) {
super(args, opts);
opts.env.configuration = {};
}
```
### `opts.env.configuration.myObj` (required)

`myObj` is your scaffold. This is where you will add options for the CLI to transform into a configuration. You can name it anything, and you can also add more objects, that could represent a `dev.config` or `prod.config`.

```js
constructor(args, opts) {
super(args, opts);
opts.env.configuration = {
dev: {},
prod: {}
};
}
```

### `myObj.webpackOptions` (required)

As with a regular webpack configuration, this property behaves the same. Inside `webpackOptions` you can declare the properties you want to scaffold. You can for instance, scaffold `entry`, `output` and `context`.

(Inside a yeoman method)
```js
this.options.env.configuration.dev.webpackOptions = {
entry: '\'app.js\'',
output: {....},
merge: 'myConfig'
};
```
If you want to use `webpack-merge`, you can supply `webpackOptions` with the merge property, and the configuration you want to merge it with.

### `myObj.topScope`(optional)

The `topScope` property is a way for the authors to add special behaviours, like functions that could be called inside a configuration, or variable initializations and module imports.

```js
this.options.env.configuration.dev.topScope = [
'var webpack = require(\'webpack\');'
'var path = require(\'path\');'
];
```

### `myObj.configName`(optional)

If you want to name your `webpack.config.js` something special, you can do that.

```js
this.options.env.configuration.dev.configName = 'base';
```
12 changes: 3 additions & 9 deletions bin/config-yargs.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ module.exports = function(yargs) {
requiresArg: true
},
'env': {
describe: 'Enviroment passed to the config, when it is a function',
describe: 'Environment passed to the config, when it is a function',
group: CONFIG_GROUP
},
'context': {
Expand Down Expand Up @@ -149,7 +149,7 @@ module.exports = function(yargs) {
},
'target': {
type: 'string',
describe: 'The targeted execution enviroment',
describe: 'The targeted execution environment',
group: ADVANCED_GROUP,
requiresArg: true
},
Expand All @@ -166,12 +166,6 @@ module.exports = function(yargs) {
describe: 'Watch the filesystem for changes',
group: BASIC_GROUP
},
'save': {
type: 'boolean',
alias: 's',
describe: 'Rebuilds on save regardless of changes in watch mode',
group: BASIC_GROUP
},
'watch-stdin': {
type: 'boolean',
alias: 'stdin',
Expand All @@ -185,7 +179,7 @@ module.exports = function(yargs) {
},
'watch-poll': {
type: 'boolean',
describe: 'The polling intervall for watching (also enable polling)',
describe: 'The polling interval for watching (also enable polling)',
group: ADVANCED_GROUP
},
'hot': {
Expand Down
43 changes: 18 additions & 25 deletions bin/convert-argv.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ module.exports = function(yargs, argv, convertOptions) {
function processConfiguredOptions(options) {
if(options === null || typeof options !== 'object') {
console.error('Config did not export an object or a function returning an object.');
process.exit(-1);
process.exitCode = -1;
}

// process Promise
Expand Down Expand Up @@ -224,16 +224,10 @@ module.exports = function(yargs, argv, convertOptions) {
options[optionName || name] = false;
});
}
//eslint-disable-next-line
function mapArgToPath(name, optionName) {
ifArg(name, function(str) {
options[optionName || name] = path.resolve(str);
});
}

function loadPlugin(name) {
var loadUtils = require('loader-utils');
var args = null;
var args;
try {
var p = name && name.indexOf('?');
if(p > -1) {
Expand All @@ -242,7 +236,7 @@ module.exports = function(yargs, argv, convertOptions) {
}
} catch(e) {
console.log('Invalid plugin arguments ' + name + ' (' + e + ').');
process.exit(-1);
process.exitCode = -1;
}

var path;
Expand All @@ -251,7 +245,7 @@ module.exports = function(yargs, argv, convertOptions) {
path = resolve.sync(process.cwd(), name);
} catch(e) {
console.log('Cannot resolve plugin ' + name + '.');
process.exit(-1);
process.exitCode = -1;
}
var Plugin;
try {
Expand Down Expand Up @@ -281,7 +275,11 @@ module.exports = function(yargs, argv, convertOptions) {
}

ifArgPair('entry', function(name, entry) {
options.entry[name] = entry;
if(typeof options.entry[name] !== 'undefined' && options.entry[name] !== null) {
options.entry[name] = [].concat(options.entry[name]).concat(entry);
} else {
options.entry[name] = entry;
}
}, function() {
ensureObject(options, 'entry');
});
Expand Down Expand Up @@ -322,7 +320,7 @@ module.exports = function(yargs, argv, convertOptions) {

ifArg('output-path', function(value) {
ensureObject(options, 'output');
options.output.path = value;
options.output.path = path.resolve(value);
});

ifArg('output-filename', function(value) {
Expand Down Expand Up @@ -454,7 +452,7 @@ module.exports = function(yargs, argv, convertOptions) {

ifArg('prefetch', function(request) {
ensureArray(options, 'plugins');
var PrefetchPlugin = require('webpack/PrefetchPlugin');
var PrefetchPlugin = require('webpack/lib/PrefetchPlugin');
options.plugins.push(new PrefetchPlugin(request));
});

Expand All @@ -468,16 +466,10 @@ module.exports = function(yargs, argv, convertOptions) {
} else {
name = value;
}
var ProvidePlugin = require('webpack/ProvidePlugin');
var ProvidePlugin = require('webpack/lib/ProvidePlugin');
options.plugins.push(new ProvidePlugin(name, value));
});

ifBooleanArg('labeled-modules', function() {
ensureArray(options, 'plugins');
var LabeledModulesPlugin = require('webpack/lib/dependencies/LabeledModulesPlugin');
options.plugins.push(new LabeledModulesPlugin());
});

ifArg('plugin', function(value) {
ensureArray(options, 'plugins');
options.plugins.push(loadPlugin(value));
Expand All @@ -490,19 +482,20 @@ module.exports = function(yargs, argv, convertOptions) {
if(noOutputFilenameDefined) {
ensureObject(options, 'output');
if(convertOptions && convertOptions.outputFilename) {
options.output.path = path.dirname(convertOptions.outputFilename);
options.output.path = path.resolve(path.dirname(convertOptions.outputFilename));
options.output.filename = path.basename(convertOptions.outputFilename);
} else if(argv._.length > 0) {
options.output.filename = argv._.pop();
options.output.path = path.dirname(options.output.filename);
options.output.path = path.resolve(path.dirname(options.output.filename));
options.output.filename = path.basename(options.output.filename);
} else if(configFileLoaded) {
throw new Error('\'output.filename\' is required, either in config file or as --output-filename');
} else {
}
else {
console.error('No configuration file found and no output filename configured via CLI option.');
console.error('A configuration file could be named \'webpack.config.js\' in the current directory.');
console.error('Use --help to display the CLI options.');
process.exit(-1);
process.exitCode = -1;
}
}

Expand Down Expand Up @@ -549,7 +542,7 @@ module.exports = function(yargs, argv, convertOptions) {
console.error('A configuration file could be named \'webpack.config.js\' in the current directory.');
}
console.error('Use --help to display the CLI options.');
process.exit(-1);
process.exitCode = -1;
}
}
};
8 changes: 4 additions & 4 deletions bin/process-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ module.exports = function processOptions(yargs, argv) {
console.error('\u001b[1m\u001b[31m' + e.message + '\u001b[39m\u001b[22m');
else
console.error(e.message);
process.exit(1);
process.exitCode = 1;
}
throw e;
}
Expand All @@ -160,7 +160,7 @@ module.exports = function processOptions(yargs, argv) {
lastHash = null;
console.error(err.stack || err);
if(err.details) console.error(err.details);
process.exit(1);
process.exitCode = 1;
}
if(outputOptions.json) {
process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + '\n');
Expand All @@ -172,7 +172,7 @@ module.exports = function processOptions(yargs, argv) {
}
if(!options.watch && stats.hasErrors()) {
process.on('exit', function() {
process.exit(2);
process.exitCode = 2;
});
}
}
Expand All @@ -181,7 +181,7 @@ module.exports = function processOptions(yargs, argv) {
var watchOptions = primaryOptions.watchOptions || primaryOptions.watch || {};
if(watchOptions.stdin) {
process.stdin.on('end', function() {
process.exit(0);
process.exitCode = 0;
});
process.stdin.resume();
}
Expand Down
Loading