Giter VIP home page Giter VIP logo

webpack-command's Introduction

npm node deps tests coverage chat size

webpack-command

DEPRECATED. Please use webpack-cli. If any features were not implemented in webpack-cli feel free to create issue.

Why deprecated webpack-command ?

  • webpack-cli is very stable and have more features.
  • Two CLIs are misleading for developers.
  • Hard to maintain two package with same purpose.
  • The author stopped developing the package.
  • Most of the features are already implemented in webpack-cli.

Thanks for using webpack! We apologize for the inconvenience. In the future, we will avoid such situations.


A superior CLI experience for webpack. Lightweight, modular, and opinionated.

For users coming from webpack-cli, please read about the differences between this module and webpack-cli.

Requirements

This module requires a minimum of Node v6.14.0 and Webpack v4.0.0.

webpack-command and webpack-cli cannot be installed at the same time, as they both export a bin file named webpack. When trying webpack-command, please npm uninstall webpack-cli first.

Benefits

webpack-command has many advantages over other CLI experiences for webpack. These include:

  • Extendable Webpack Configurations. A configuration file can extend the properties and collections from base configurations, and are filtered intelligently.
  • Custom Reporters 🤯
  • A beautiful default user experience with output driven by webpack-stylish
  • Support for webpack configuration in any language or compiler that provides a require hook
  • Support for webpack configuration in JSON, YAML, or JavaScript
  • Validation of commands, entries, and flags before further execution
  • Extensible third-party commands. Include only what you need!
  • A full test suite with 220 tests and 95% coverage (so close to 100% 💪)
  • A 93% 24% smaller package cost versus webpack-cli (it used to be 93%, they got wise after webpack-command was released)
  • Highly focused on the User Experience and detail

And last but not least, Did-You-Mean suggestions for flags:

did you mean

Getting Started

To begin, you'll need to install webpack-command:

$ npm install webpack-command --save-dev

CLI

The primary binary for webpack-command is wp (because who doesn't like to save keystrokes!?) Although, you may also use the webpack binary as per usual if your setup installs this module after webpack, and the two don't conflict.

$ wp --help

  A superior CLI experience for webpack. Lightweight, modular, and opinionated.

  Usage
    $ webpack [<config>, ...options]
    $ webpack <entry-file> [...<entry-file>] <output-file>
    $ webpack <command> [...options]

  Options
    --context                     The root directory for resolving entry point and stats
    --debug                       Switch loaders to debug mode
    --devtool                     Enable devtool for better debugging experience.
                                  e.g. --devtool eval-cheap-module-source-map
    --entry                       The entry point
    --help                        Show usage information and the options listed here
    --log-level                   Limit all process console messages to a specific level and above
                                  Levels: trace, debug, info, warn, error, silent
    --log-time                    Instruct the logger for webpack-serve and dependencies to display a timestamp
    --progress                    Instructs webpack to track and display build progress
    --reporter                    Specifies the reporter to use for generating console output for a build
    --require                     Preload one or more modules before loading the webpack configuration
                                  Typically used for language-specific require hooks
    --run-dev                     An alias for --debug --devtool eval-cheap-module-source-map --output-pathinfo
    --run-prod                    An alias for --optimize-minimize --define process.env.NODE_ENV="production"
    --version                     Display the webpack-command version
    --watch                       Watch the filesystem for changes

  Advanced
    --bail                        Abort the compilation on first error
    --cache                       Enable in memory caching
    --define                      Define any free var in the bundle
    --hot                         Enables Hot Module Replacement
    --plugin                      Load this plugin
    --prefetch                    Prefetch this request
                                  e.g. --prefetch ./file.js
    --profile                     Profile the compilation and include information in stats
    --provide                     Provide these modules as free vars in all modules
                                  e.g. --provide.jQuery jquery
    --records-input-path          Path to the records file (reading)
    --records-output-path         Path to the records file (writing)
    --records-path                Path to the records file
    --target                      The targeted execution environment
    --watch-aggregate-timeout     Timeout for gathering changes while watching
    --watch-poll                  The polling interval for watching (also enable polling)
    --watch-stdin                 Exit the process when stdin is closed

  Configuration File
    --config                      Path to the config file
    --config-name                 Name of the config to use
    --config-register             Deprecated. Please use --require.
    --mode                        Specifies the build mode to use; development or production

  Modules
    --module-bind                 Bind an extension to a loader
    --module-bind-post            Bind an extension to a postLoader
    --module-bind-pre             Bind an extension to a preLoader

  Optimization
    --optimize-max-chunks         Try to keep the chunk count below a limit
    --optimize-min-chunk-size     Try to keep the chunk size above a limit
    --optimize-minimize           Minimize javascript and switches loaders to minimizing

  Output
    --output                      The output path and file for compilation assets
    --output-chunk-filename       The output filename for additional chunks
    --output-filename             The output filename of the bundle
    --output-jsonp-function       The name of the JSONP function used for chunk loading
    --output-library              Expose the exports of the entry point as library
    --output-library-target       The type for exposing the exports of the entry point as library
    --output-path                 The output path for compilation assets
    --output-pathinfo             Include a comment with the request for every dependency (require, import, etc.)
    --output-public-path          The public path for the assets
    --output-source-map-filename  The output filename for the SourceMap

  Resolver
    --resolve-alias               Setup a module alias for resolving
                                  e.g. --resolve-alias.jquery jquery.plugin
    --resolve-extensions          Setup extensions that should be used to resolve modules
                                  e.g. .es6,.js
    --resolve-loader-alias        Setup a loader alias for resolving


    For further documentation, visit https://webpack.js.org/api/cli

  Commands
    help
    teach

    Type `webpack help <command>` for more information

As a convenience for alternative package managers, the webpack-command binary is also installed with this package.

Extendable Webpack Configurations

This module supports extending webpack configuration files with ESLint-style extends functionality. This feature allows users to create a "base" config and in essence, "inherit" from that base config in a separate config. A bare-bones example:

// base.config.js
module.exports = {
  name: 'base',
  mode: 'development',
  plugins: [...]
}
// webpack.config.js
module.exports = {
  extends: path.join(..., 'base-config.js'),
  name: 'dev'

The resulting configuration object would resemble:

{
  name: 'dev',
  mode: 'development',
  plugins: [...]
}

Read More about Extending Configuration Files

Commands

webpack-command allows users to extend the webpack CLI experience by including a few helpful built-in commands, and providing a means to develop third-party commands.

Built-In Commands

Flags

For more documentation on flags, please see the webpack-cli documentation.

Differences With webpack-cli

While this project aims for parity with webpack-cli in nearly all aspects, there are some notable differences. Included in those differences is the note that this module includes the bare minimum of commands to provide a webpack CLI. Commands like init, migrate, and update are relegated to separate, user-installed modules.

That said, the following differences should also be noted:

The --env Flag is Nuked

Environment Variables have been around a very, very long time. webpack-cli chose to introduce a feature that let users specify environment variables via a flag. This module does not include that feature. Instead, users should make use of environment variables the traditional, standard way:

$ NEAT_VAR=woo webpack ...

And access the values via process.env. Alternatively, if users are in need of cross-platform environment variables, a tool such as cross-env should be leveraged.

Key=Value Pairs

Certain flags passed in webpack-cli allow for a key-value pair for pairing an alias with the alias value. e.g. --entry name=file. This module adopts a CLI-standard approach by using the syntax --flag.key value instead, and does not support the key=value syntax.

Entries

Specifying entries by either flag (--flag) or input (webpack <file>) require that the file or directory specified exist.

Entries passed with a comma-separated value --entry file,file2 are deprecated and should be migrated to use the CLI-standard --entry file --entry file2 syntax.

Entries passed by flag in webpack-cli using --entry name=file should be migrated to use the --entry.name file syntax.

Resolve Alias

Resolve aliases passed by flag in webpack-cli using --resolve-alias alias=value should be migrated to use the --resolve-alias.{alias} {value} syntax.

Resolve Loader Alias

Resolve aliases passed by flag in webpack-cli using --resolve-loader-alias alias=value should be migrated to use the --resolve-loader-alias.alias value syntax.

Reporters

webpack-command supports custom, user-defined reporters which allow users full control over how build data is presented. By default, it ships with two available reporters:

basic

Displays the default webpack output, the same you'll see using webpack-cli.

stylish

The default reporter and displays beautiful output using the same code that drives webpack-stylish.

Building your own reporter is as easy as inheriting from the Reporter class located at lib/reporters/Reporter.js.

Configuration Languages and Compilers

webpack-command allows users to leverage any language that provides a require hook. To leverage this feature, define your configs as such for the following languages/compilers:

  • Babel ES6 Modules: webpack.config.js or webpack.config.es6, and use --require babel-register
  • Flow: webpack.config.js or webpack.config.flow, and use --require flow-remove-types/register
  • TypeScript: webpack.config.ts, and use --require ts-node/register

Other hooks may work for additional language or compiler support.

Note: Compilers are not part of, nor built-into this module. To use a specific compiler, you must install it first.

Gotchas

Any entry files specified will overwrite entries in a webpack.config.js file as of this Pull Request in webpack-cli.

Contributing

Please take a moment to read our contributing guidelines if you haven't yet done so.

License

webpack-command's People

Contributors

deekthesqueak avatar dhruvdutt avatar elliottsj avatar evenstensberg avatar evilebottnawi avatar mitalie avatar ooflorent avatar sendilkumarn avatar shellscape avatar styfle avatar vitalyster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webpack-command's Issues

Tests

This issue tracks which tests are outstanding and need implementation:

Misc

  • did you mean
  • invalid flag type
  • invalid webpack options
  • zero config
  • stylish reporter with multiple builds (MultiCompiler)

Done

Options

  • --context
  • --debug
  • --devtool
  • --entry
    • single
    • multiple
  • --help
  • --reporter
  • --log-level
  • --log-time
  • --run-dev
  • --run-prod
  • --version

Advanced

  • --bail
  • --cache
  • --define
  • --hot
  • --plugin
  • --prefetch
  • --profile
  • --provide
  • --records-input-path
  • --records-output-path
  • --records-path
  • --target
  • --watch
    • config.watch, when specified in config and not a flag
  • --watch-aggregate-timeout
  • --watch-poll
  • --watch-stdin

Configuration File

  • --config
  • --config-name
  • --mode

Modules

  • --module-bind
  • --module-bind-post
  • --module-bind-pre

Optimization

  • --optimize-max-chunks
  • --optimize-min-chunk-size
  • --optimize-minimize

Output

  • --output
  • --output-chunk-filename
  • --output-filename
  • --output-jsonp-function
  • --output-library
  • --output-library-target
  • --output-path
  • --output-pathinfo
  • --output-public-path
  • --output-source-map-filename

Resolver

  • --resolve-alias
  • --resolve-extensions
  • --resolve-loader-alias

Reporters

  • stylish
  • basic

Commands

  • help
    • test help help and help teach for sanity
    • no opens docs site
  • teach
    • --command <command> --module <module>
    • --command and --module value types
    • missing --command or --module
    • --forget

ESLint expects LF line endings but repository checks out CRLF on Windows

  • Operating System: Windows 7 SP1
  • Node Version: 10.1.0
  • NPM Version: 6.1.0
  • webpack Version: 4.6.0
  • webpack-command Version: 0.2.1

This issue is for a:

  • bug
  • feature request
  • modification request

Code

webpack.config.js

N/A

Expected Behavior

The checked out repository should have LF line endings.

Actual Behavior

The checked out repository has CRLF line endings on Windows.

How Do We Reproduce?

git clone or git checkout on Windows.

Allow a way to disable update-notifier

  • Operating System: Linux
  • Node Version: 8.9.1
  • NPM Version: n/a
  • webpack Version: 4.8.1
  • webpack-command Version: 0.2.0

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command

I run build steps under a containerized filesystem sandbox (this is for the Bazel build which does this to enable remote build execution.)

I suspect that's why any execution of webpack-command prints

┌──────────────────────────────────────────────────────────────────────────────┐
│                     webpack-command update check failed                      │
│                     Try running with sudo or get access                      │
│                     to the local update config store via                     │
│ sudo chown -R $USER:$(id -gn $USER) /usr/local/google/home/alexeagle/.config │
└──────────────────────────────────────────────────────────────────────────────┘

Expected Behavior

Either update-notifier should be quiet when it's running in a context where it can't work (not sure if feasible)
or webpack-command would let me disable this output, either directly or via --log-level or --reporter

Actual Behavior

Always get this ugly error for any build step that runs webpack-command

How Do We Reproduce?

webpack output contains duplicated dependencies after upgrading to 0.3.0

  • Operating System: Windows 10
  • Node Version: 8.11.3
  • NPM Version: 5.6.0
  • webpack Version: 4.12.2
  • webpack-command Version: 0.3.0

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ webpack -p
webpack.config.js

https://gist.github.com/vitalyster/9524813d2905f827246623084296e25e - here is the demo app including webpack.config.js

Expected Behavior

My app uses react, output have app.js and vendor.js chunks, vendor.js should contain react.production.min.js and react-dom.production.min.js (copyright comments containing these names should be there too). webpack-cli and [email protected] are working as expected

Actual Behavior

After upgrading from 0.2.1 to 0.3.0 output contains react(-dom).production AND react-(dom).development

How Do We Reproduce?

  1. npm run dist in my gist directory and check dist/ directory
  2. npm install --save-dev [email protected] && npm run dist will make correct output

Can't install webpack-command as global module

  • Operating System: macos
  • Node Version: latest
  • NPM Version: latest
  • webpack Version: latest
  • webpack-command Version: latest

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command

n/a

Expected Behavior

Module is usable

Actual Behavior

webpack -h # Error: Cannot find module 'enhanced-resolve' 

How Do We Reproduce?

npm i webpack -g
npm i webpack-command -g

Reporter Needs

Reporters should be given the config and the compiler on instantiation.

Reporters should use a commonly defined log object. This will keep them all standardized and avoid the console.log vs stdout mess in mocha. Preferably an instance of webpack-log without a prefix and indicator icon. That's not currently possible, so webpack-log will probably have to be updated.

Should reporters should also have access to log-symbols without having to declare a need for them explicitly?

Support dynamic entry

  • Operating System: Linux
  • Node Version: 8.9.1
  • NPM Version: 6.1.0
  • webpack Version: 4.16.3
  • webpack-command Version: 0.4.1

Dynamic entry does not work due to a glitch sanitizing the configuration. This seems to be used most often to have webpack pick up globbed entry points (example package; getEntries returns a function).

CLI Command

  $ wp

Code

// webpack.config.js
const { resolve } = require('path');

exports.default = {
    entry: () => resolve(__dirname, 'src/another-missing-file.js'),
}

Expected Behavior

Can't resolve '.../src/another-missing-file.js'

Works as expected with webpack-cli.

Actual Behavior

Error: Can't resolve './src'

How Do We Reproduce?

Function has no enumerable properties, so will be discarded by compiler.js#L83

Believe adding a typeof target === 'object' check is the safe fix. I have a local fix with test if you'd like me to throw up a fork and PR.

Resolve extended configs via eslint-import-resolver-webpack (or make similar plugin)

  • Operating System: Ubuntu 18.04 n/a
  • Node Version: 8 n/a
  • NPM Version: 6 n/a
  • webpack Version: 4 n/a
  • webpack-command Version: 0.4.1

Expected Behavior / Situation

eslint-import-resolver-webpack should understand webpack-command's extends config.

Actual Behavior / Situation

eslint-import-resolver-webpack does not understand webpack-command's extends config. This results in messages like this:

  6:21  error  Unable to resolve path to module 'components/AppRoot'  import/no-unresolved

Modification Proposal

Either:

1️⃣ Make eslint-import-resolver-webpack compatible with this plugin's features (namely: extends).

2️⃣ Make a similar plugin which is compatible with this plugin's features (namely: extends).


NOTE Not sure if this is better in eslint-import-resolver-webpack's issues or here, so I'm making one here since this project added the extends functionality.

feat: `--progress` option

  • Operating System: ubuntu 17.10
  • Node Version: 10.0.0
  • NPM Version: 6.0.0
  • webpack Version: 4.6.0
  • webpack-command Version: 0.1.

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ webpack
webpack.config.js

no required

Expected Behavior

Similar as webpack-cli

Actual Behavior

✖ 「webpack」: Flags were specified that were not recognized:

  --progress  Not sure what you mean there

How Do We Reproduce?

no required

New Feature Use Case

Looks what is happens right now and build stage.

Not respecting `context` in webpack.config.js

  • Operating System: macOS 10.13.4
  • Node Version: v10.4.1
  • Yarn Version: 1.6.0
  • webpack Version: 4.12.0
  • webpack-command Version: 0.2.1

This issue is for a:

  • bug
  • feature request
  • modification request

Code

https://github.com/alexilyaev/react-es6-starter/tree/webpack-command-context-bug

CLI Command
  $ npm run build
webpack.config.js

https://github.com/alexilyaev/react-es6-starter/blob/webpack-command-context-bug/webpack.config.js

Expected Behavior

npm run build should succeed.

Actual Behavior

Fails with:

> cross-env NODE_ENV=production webpack

clean-webpack-plugin: /Users/alex/www/Node/Personal/react-es6-starter/dist has been removed.
ℹ 「webpack」: Starting Build
ℹ 「webpack」: Build Finished

webpack v4.12.0

475330bd3c812c147ff4
  size  name  module  status

  Δt 581ms


Entry module not found: Error: Can't resolve './app.js' in '/Users/alex/www/Node/Personal/react-es6-starter'
  0:0  error  webpack-stylish: <please report unknown message format>

Error: Child compilation failed:
  253:16  error  Entry module not found: Error: Can't resolve
                 '/Users/alex/www/Node/Personal/react-es6-starter/app.html' in
                 '/Users/alex/www/Node/Personal/rea  ct-es6-starter':   Error: Can't
                 resolve '/Users/alex/www/Node/Personal/react-es6-starter/app.html' in
                 '/Users/alex/www/Node/Personal/react-es6-starter'      - compiler.js:79
                 childCompiler.runAsChild
                 [react-es6-starter]/[html-webpack-plugin]/lib/compiler.js:      -
                 Compiler.js:243 compile
                 [react-es6-starter]/[webpack]/lib/Compiler.js:243:11      -
                 Compiler.js:500 hooks.afterCompile.callAsync.err
                 [react-es6-starter]/[webpack]/lib/Compiler.js:500:14         -
                 Hook.js:35 AsyncSeriesHook.lazyCompileHook [as _callAsync]
                 [react-es6-starter]/[tapable]/lib/Hook.js:35:21      - Compiler.js:497
                 compilation.seal.err
                 [react-es6-starter]/[webpack]/lib/Compiler.js:497:30         -
                 Hook.js:35 AsyncSeriesHook.lazyCompileHook [as _callAsync]
                 [react-es6-starter]/[tapable]/lib/Hook.js:35:21      -
                 Compilation.js:986 hooks.optimizeAssets.callAsync.err
                 [react-es6-starter]/[webpack]/lib/Compilation.js:986:35         -
                 Hook.js:35 AsyncSeriesHook.lazyCompileHook [as _callAsync]
                 [react-es6-starter]/[tapable]/lib/Hook.js:35:21      -
                 Compilation.js:977 hooks.optimizeChunkAssets.callAsync.err
                 [react-es6-starter]/[webpack]/lib/Compilation.js:977:32         -
                 index.js:334
                 [react-es6-starter]/[uglifyjs-webpack-plugin]/dist/index.js:334:11
                 - index.js:63 _class.runTasks
                 [react-es6-starter]/[uglifyjs-webpack-plugin]/dist/uglify/index.js:63:9
                 - index.js:253 UglifyJsPlugin.optimizeFn

✖ 2 problems (2 errors, 0 warnings)

How Do We Reproduce?

  • Clone
  • yarn
  • npm run build

Other Notes

  • context is not respected
  • Works ok with webpack-cli

Error using hyphen in entry flag of type object

  • Operating System: OSX
  • Node Version: 9.11.1
  • NPM Version: 6.2.0
  • webpack Version: 4.16.1
  • webpack-command Version: 0.4.1

CLI Command

  $ wp --mode development --entry.base-common ./scripts/base-common.js

Expected Behavior

Generate ./dist/base-common.js.

Actual Behavior

ERROR:

✖ 「webpack」: Flags were specified that were not recognized:

  --entry-base-common  Not sure what you mean there

Code

  // webpack.config.js: NO
  // base-common.js
  console.log("It's work!");

I think that the problem is in ./lib/flags/utils.js » validateFlags.

Define parameter returns error: "error --define must be set to a object"

  • Operating System: Mac OS
  • Node Version: 9.7.1
  • NPM Version: 5.6.0
  • webpack Version: 4.12.0
  • webpack-command Version: 0.2.1

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ webpack --define process.env.BROWSER="chrome"
webpack.config.js

Note: Irrelevant because webpack-command exits before the config is loaded.

const path = require('path');
module.exports = {
    entry: {
        app: './app.js',
    },
    output: {
        filename: '[name].js',
    }
};

Expected Behavior

No errors, process.env.BROWSER is accessible and populated in app.js.

Actual Behavior

$ webpack  --define process.env.BROWSER="chrome"
✖ 「webpack」: Flags were specified with invalid values:

  --define must be set to a object

Please check the command executed.

How Do We Reproduce?

Pass any --define process.env.<NAME>="<VALUE>" to webpack using the command line or from within a package.json script.

Documentation for --run-dev and --run-prod is confusing due to inconsistency

  • Operating System: Mac OS
  • Node Version: 8.11.1
  • NPM Version: 5.8.0
  • webpack Version: 4.6.0
  • webpack-command Version: 0.1.0

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ webpack --run-dev
  $ webpack --run-prod
webpack.config.js
const webpack = require('webpack')

module.exports = {
  context: __dirname + "/src",
  entry: "./index",
  output: {
    path: __dirname + "/dist",
    filename: "bundle.js"
  },
  module: {
    loaders: [
      {
        test: /\.js$/
      }
    ]
  }
}

Expected Behavior

  • --run-dev in the documentation includes that it sets --define process.env.NODE_ENV="development", to be consistent with the --run-prod documentation.

Or alternatively:

  • --run-dev in the documentation includes that it sets the mode to "development"
  • --run-prod in the documentation includes that it sets the mode to "production"
  • --run-prod in the documentation removes the --define process.env.NODE_ENV=... notion (as this done by Webpack, not by Webpack Command).
  • Optional: --mode in the documentation includes the --define process.env.NODE_ENV=... notion or includes a link to https://webpack.js.org/concepts/mode/

Actual Behavior

  • --run-dev and --run-prod in the documentation both don't mention Webpack mode
  • --run-dev doesn't mention --define process.env.NODE_ENV=... whereas --run-prod does

Environment variables don't seem to work

  • Operating System: OSX
  • Node Version: 10.3.0
  • NPM Version: 6.0.1
  • webpack Version: 4.10.2
  • webpack-command Version: 0.2.0

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ FOO='bar' webpack
webpack.config.js

None...

Other code

src/index.js:

console.log(process.env.FOO) // undefined

Also doesn't work:

console.log(process.env) // {}

Expected Behavior

This code, according to docs, should log 'bar' to the console.

Actual Behavior

It actually logs undefined, which is unexpected.

How Do We Reproduce?

Doing above

'mode' is not found in multi compiler configuration

  • Operating System: macOS 10.13.5
  • Node Version: 9.5.0
  • NPM Version: 6.1.0
  • webpack Version: 4.11.0
  • webpack-command Version: 0.2.0

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ webpack
webpack.config.js
module.exports = [
  {
    mode: 'production',
    entry: './index.js',
    output: {
      filename: 'lib-prod.js'
    },
  },
  {
    mode: 'development',
    entry: './index.js',
    output: {
      filename: 'lib-dev.js'
    },
  },
];
// index.js
console.log('start');

if (process.env.NODE_ENV !== 'production') {
  console.log('dev mode');
}

Expected Behavior

I expect this configuration to run two builds, one in dev mode and one in prod mode.

See this example for a more realistic use of a multi compiler setup https://github.com/webpack/webpack/tree/master/examples/multi-compiler

Actual Behavior

A warning for each entry is logged:

  0:0  warning  The 'mode' option has not been set, webpack will fallback to
                'production' for this value. Set 'mode' option to 'development' or
                'production' to enable defaults for each environment.

And each build output is indeed built in production mode.

The build works as expected using webpack-cli

How Do We Reproduce?

Run the provided cli command with the webpack config and source file.

Arguments not passed to webpack config

  • Operating System: Windows 10
  • Node Version: 9.11.1
  • NPM Version: 5.6.0
  • webpack Version: 4.10.0
  • webpack-command Version: 0.2.0

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ webpack --mode=production
webpack.config.js
module.exports = function (argv) {
  const production = argv.mode === 'production'
  ...
}

Expected Behavior

Function should be called with arguments passed to CLI, just like with webpack-cli. For example:

 { mode: 'production' }

Actual Behavior

Function is called without arguments.

How Do We Reproduce?

Export function from webpack config.

Investigation

I can see that webpack-command uses config-loader for loading webpack config.
config-loader has this functionality described in https://github.com/webpack-contrib/config-loader#gotchas, but as far as I can see, default exported function from config-loader does not actually call config with arguments. webpack-command does not pass them to config-loader either. So I'm sure where to report this bug.

Support JSON stats output

  • Operating System: macOS 10.13.4
  • Node Version: 10.0.0
  • NPM Version: 6.0.0
  • webpack Version: 4.8.1
  • webpack-command Version: 0.2.0

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ webpack --json
webpack.config.js

n/a

Expected Behavior

webpack-cli (and formerly the bundled webpack CLI) has a --json arg which causes the stats to be printed out as JSON. This is extremely useful for piping into files which can then be uploaded to web-based bundle analysis tools.

It would be great if webpack-command could support this flag or something equivalent -- perhaps through a reporter. Since webpack-command is already working with the JSON stats, I assume this would be a low-overhead feature to support.

I'm about to take a vacation but I might be able to get a PR out before I leave if this sounds reasonable to you.

Actual Behavior

There is currently no way to get the build stats as JSON.

New Feature Use Case

See expected behavior above.

Not respecting 'stats' configuration

  • Operating System: Windows 10 x64
  • Node Version: 8.11.1
  • Yarn Version: 1.6.0
  • webpack Version: 4.8.3
  • webpack-command Version: 0.2.0

This issue is for a:

  • bug
  • feature request
  • modification request

Code

CLI Command
  $ webpack --mode development
webpack.config.js
module.exports = {
  // ...
  stats: {
    modules: false,
  },
};

Expected Behavior

Matching (somewhat) to what webpack-cli outputs, namely that the modules would not be printed out.

(using webpack-cli)

$ webpack --mode development
Hash: 023831cded95754adc9d
Version: webpack 4.8.3
Time: 2876ms
Built at: 2018-05-23 13:42:59
     Asset       Size  Chunks             Chunk Names
  main.css    140 KiB    main  [emitted]  main
   main.js   1.75 MiB    main  [emitted]  main
index.html  485 bytes          [emitted]
Entrypoint main = main.css main.js
Done in 4.06s.

Actual Behavior

Modules are still outputted

(using webpack-command)

$ webpack --mode development
i 「webpack」: Starting Build
i 「webpack」: Build Finished

webpack v4.8.3

023831cded95754adc9d
  size     name                   module                                               status
  509 B    global.js              (webpack)/buildin/global.js                          built
  563 B    app.js                 ./public/js/app.js                                   built
  ... (list of 13 other modules imported)...

  size     name                   asset                                                status
  144 kB   main                   main.css                                             emitted
  1.83 MB  main                   main.js                                              emitted
  485 B    html                   index.html                                           emitted

  Δt 2827ms (142 modules hidden)

Done in 4.15s.

How Do We Reproduce?

Create a webpack.config.js that specifies a stats configuration. Notice that it is not respected.

Error stacktraces aren't showing up

  • Operating System: Windows 10
  • Node Version: 8
  • NPM Version: 6
  • webpack Version: 4
  • webpack-command Version: 0.4.0

CLI Command

  $ webpack --mode development --watch

Expected Behavior

If an error occurs, the full stack trace should be shown, to be able to solve the issue.
webpack-cli outputs the following:


WARNING in ./src/design-tokens/colors.docs.md
Module build failed (from D:/Projects/fabricator-builder/node_modules/extract-loader/lib/extractLoader.js):
ModuleBuildError: Module build failed (from D:/Projects/fabricator-builder/node_modules/vue-loader/lib/index.js):
Error: Cannot find module 'vue-template-compiler'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
....

Actual Behavior

I got this on console, and I can't find any file that output more:

  0:0  error  Module build failed (from
              D:/Projects/fabricator-builder/node_modules/vue-loader/lib/index.js):

How Do We Reproduce?

Make sure one of the loaders gives an error.

exit code is always 0

  • Operating System: Ubuntu 18.04
  • Node Version: v8.10.0
  • NPM Version: 6.0.0
  • webpack Version: 4.9.1
  • webpack-command Version: 0.2.0

This issue is for a:

  • bug
  • feature request
  • modification request

Expected Behavior

If any errors occurs I expect some exit code > 0.

Actual Behavior

exit code is 0

How Do We Reproduce?

put some invalid code before running webpack

New Feature Use Case

Config errors when installed alongside postcss-loader

  • Operating System: 10.13.4
  • Node Version: 10.0.0
  • NPM Version: 6.0.0
  • webpack Version: 4.6.0
  • webpack-command Version: 0.1.1

This issue is for a:

  • bug
  • feature request
  • modification request

Code

See this minimal reproducing repo.

CLI Command
  $ webpack
webpack.config.js
module.exports = {
  entry: './foo',
  mode: 'development',
}

Expected Behavior

The presence of an unrelated dependency shouldn't affect webpack-command's ability to function.

Actual Behavior

In the initial commit, npx webpack works fine. However, after the following commit, which just adds postcss-loader as a dependency, npx webpack breaks, yielding the following error:

Entry module not found: Error: Can't resolve './src' in '/Users/billy/work/foo'
  0:0  error  webpack-stylish: <please report unknown message format>

configuration
  0:0  warning  The 'mode' option has not been set, webpack will fallback to
                'production' for this value. Set 'mode' option to 'development' or
                'production' to enable defaults for each environment.

It seems that the config is no longer being passed to webpack. Interestingly, if you add a console.log statement to webpack.config.js, it does run, so the config is still being parsed but not passed.

This might be an issue with how webpack-command is loading its dependencies (or how one of its dependencies is loading its dependencies). Perhaps a dependency is somehow being loaded relative to the CWD rather than relative to the file requiring it, such that it's getting an unexpected, incompatible version. (Looking at the package-lock.json diff, parse-json and require-from-string seem like likely offenders.) Definitely a weird bug. 🤷‍♂️

How Do We Reproduce?

Clone the repo, and flip between the two commits, running npm i && npx webpack for each.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.