New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gulp-webpack-tasks-ootb

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-webpack-tasks-ootb

Gulp Webpack Tasks out-of-box

  • 0.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-94.12%
Maintainers
1
Weekly downloads
 
Created
Source

Gulp Webpack Tasks out-of-box

Get tired of doing webpack config, babel, karma and so on ? Just want to write es6/7 code without too much configuration ? This tool is what you are looking for.

Basiclly the tool can do these for you:

  • config webpack within some default loaders, plugins; config babel within confortable presets.
  • automatically find entries and specify dist through given rules (you are still able to customize).
  • run mocha tests in karma and chrome without much configuration.
  • provide a development enviroment using webpack-dev-middleware and express.
  • compile or pack files up when you want to publish or deploy.

Usage

Basiclly, you can use the tool when you are:

  • Writing a front-end application.
  • Writing a front-end library.

You need to dev, build, or test your code, and each of these tasks is provided within a function, so you can use the tool with gulp (or other tools).

Your gulpfile may looks like:

const gulp = requir('gulp');
const tasks = requre('gulp-webpack-tasks-ootb');

const libTasks = tasks.libraryTasks({...options});

gulp.task('dev', libTasks.dev);
gulp.task('test', libTasks.test);
gulp.task('prepare', function(){
    // your local tasks
})

Tasks for writing an library

4 tasks are provided when you are writing a library: the dev task, the build task, the compile task, the test task.

You need to create these tasks by call tasks.libraryTasks(options).

options

namedescriptiontypedefault
portdev server portNumber3000
basebase directory of the projectStingprocess.cwd()
entrylibrary entry source code fileString'./src/index.js'
srcthe source code directoryString'./src'
libthe compiled (to es5, for publishing to npm) code directoryString'./lib'
demothe demo pages directory (for development or present)String'./demo'
distthe build file directory (for umd files)String'./dist'
umdNamethe library's umd nameString'foo'
devSuffixthe bundle file's suffix for development enviromentString'bundle'
buildSuffixthe bundle file's suffix for build targetString'min'
reactwhether to transform JSXBooleanfalse
loadersextra webpack loadersArray[]
pluginsextra webpack pluginsArray[]
babelPolyfillwhether to import babelPolyfillBooleanfalse
devCorswhether to enable CORS on dev serverBooleantrue
watchTestwhether to use watch mode for test taskBooleanfalse
testEntryPatternfile path pattern for test entriesString'src/**/*.spec.js'

directory structure

The main project's directory structure may looks like:

project
│   README.md
│   package.json
│   gulpfile.js
└───demo
│       foo.html
│       foo.js
│       bar.html
│       bar.js
└───dist
│       foo.min.js
└───lib
│   │   index.js
│   └───foo
│           foo.js
└───src
    │   index.js
    └───foo
            foo.js
            foo.spec.js

dev task

gulp.task('dev', libTasks.dev);

You need to put demo pages in the demo directory, which by default is './demo'. Each two files with the same basename compose a demo page, for example, foo.html and foo.js compose the foo demo. The html files looks like:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script src="./foo.bundle.js"></script>
</body>
</html>

You can modify the html file as you like but the only one you should keep is the script tag <script src="/foo.bundle.js"></script>, which is the bundled file of foo.js. The bundle suffix could be changed by devSuffix option.

The js file looks like:

import MyLib from '../src/index';
// demo code

Run gulp dev, it will open your browser with http://127.0.0.1:3000 (by default) and show the list of demos as following:

dev-ui

Click link to enter link pages and do developing.

test task

By configuring the testEntryPattern option, you can run tests in Karma and Chrome. A test file (foo.spec.js eg.) looks like:

import expect from 'expect';
import MyLib from '../src/index';

describe('mylib', function () {

    it('mylib should be ok', function(){
        expect(!!MyLib).toBeTruthy();
    });

});

Run gulp test and the test result will be ouputed to console.

build task

gulp.task('build', libTasks.build);

Run gulp build will pack your entry (by default is './src/index.js') to a umd style file and put it in dist directory. You need to provide a umdName, whick the file's name will be ${umdName.toLowercase()}.${buildSuffix}.js. If you load the umd script directly into html, then window.${umdName} is available.

compile task

gulp.task('build', libTasks.build);

If your source code contains only js file (which means you don't need extra webpack loaders to transform .less, .txt, .jpg), you can compile the source file from es6 / jsx to es5 and publish to npm for further use. At the time, you can also avoid pack dependencies to umd file. The compiled files will be put in lib directory(you can configure it by the lib option).

Run gulp compile, and compile task will be done.

Tasks for writing an appliction

3 tasks will be provided for developing an application: the dev task, the build task, the test task.

You need to create these tasks by call tasks.applicationTasks(options).

options

namedescriptiontypedefault
portdev server portNumber3000
basebase directory of the projectStingprocess.cwd()
srcthe source code directoryString'./src'
demothe demo pages directory (for development or present)String'./demo'
distthe build file directory (for umd files)String'./dist'
devSuffixthe bundle file's suffix for development enviromentString'bundle'
buildSuffixthe bundle file's suffix for build targetString'bundle'
reactwhether to transform JSXBooleanfalse
loadersextra webpack loadersArray[]
pluginsextra webpack pluginsArray[]
babelPolyfillwhether to import babelPolyfillBooleanfalse
devCorswhether to enable CORS on dev serverBooleantrue
watchTestwhether to use watch mode for test taskBooleanfalse
testEntryPatternfile path pattern for test entriesString'src/**/*.spec.js'
commonsChunkwhether to enable commonsChunk pluginBooleantrue

Compared with libaray task options, there are several differences:

  1. You don't need to provide entry option.
  2. You don't need to provide umdName option.
  3. You don't need to provide lib option.
  4. Default option of buildSuffix is bundle but not min.
  5. You can use commonsChunk option to enable commonsChunk plugin.

directory structure

The main project's directory structure may looks like:

project
│   README.md
│   package.json
│   gulpfile.js
└───demo
│       foo.html
│       foo.js
│       bar.html
│       bar.js
└───dist
│       foo.html
│       foo.bundle.js
│       bar.html
│       bar.bundle.js
└───src
    │   index.js
    └───foo
            foo.js
            foo.spec.js

Compared with library tasks, there are 2 main differences.

  1. lib directory is not necessary anymore.
  2. dist directory is a map to demo directory (for library tasks there's only 1 file ${umdName}.${buildSuffix}.js).
  3. if you enable commonsChunk plugin, the html file should also include commons file, like:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <script src="./commons.bundle.js"></script>
    <script src="./foo.bundle.js"></script>
</body>
</html>

dev task

Dev task is exactly the same with library tasks.

test task

Test task is exactly the same with library tasks.

build task

Unlike library tasks, the build task for application will pack up every page (the demo) into dist directory. It will also copy html files from demo directory to dist directory. You can deploy the js files on server, and load the js on your own page. You can also deploy the whole dist directory to some static server (gh-pages, eg), it works too.

Notice that there's no compile task for application.

If you are still confused

You may check the code in packages directory for more reference. Each of the project is an example how to use the tool.

FAQs

Package last updated on 26 Jan 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc