Webpack2 configuration
This is the configuration module for webpack2
Contributors
Dependencies
Getting Started
1. Ensure all Dependencies have been resolved.
2. Install application dependencies.
npm install webpack2-general-config
3. Import the module into your webpack configuration file.
const webpack2Config = require;
4. To use the default settings, initialize the config first. Then there will be 3 different modes of output.
const example = context: '' entry: {} outputPath: '' publicPath: '' alias: {} devServerPort: 8100 htmlPath: './index.html';
context
: The indicator for the webpack plugins to point where is your source code directory.ex. path.join(__dirname, 'app')
entry
: The entry points of your project. You can have multiple entry points, please refer to Webpack websiteex. {app:['./js/index.js']}
outputPath
: Your project's output path.ex. path.join(__dirname, 'dist')
publicPath
: Please refer to publicPath at Webpack websiteex. https://github.com/aj120426394/
alias
: Please refer to resolve.alias at Webpack websiteex. {materialize: path.resolve(__dirname, 'app/vendors/materialize/js/bin/materialize.js')}
devServerPort
: The port number you would like to use for the dev-server.ex. 8100
htmlPath
: The main HTML file of your project.ex. ./index.html
(As we set the context for the webpack, you can use relative path for rest of the setting)
5. After initialized the configuration, you can have the config output with 3 different modes.
const prodConfig = example;const devConfig = example;const devServerConfig = example;
-
buildForProduction([lib_name])
: The configuration for production which include:- Remove Package
- Set NODE_ENV as 'production'
- Minimize the JS file
- Chunk output the library (you need to provide the library's name in an array as the parameter)
-
buildForDevelopment()
: The configuration for the development which include:- inline Sourcemap
-
buildForDevServer(verbose)
: The configuration for the dev server which include:- inline Sourcemap
- Hot module replacement
6. addStyleConfig()
: The initialized configuration does not include bundling .sass .scss .css
. But you can use this function to add the style configuration.
Execute this function before execute
buildForDevServer()
,buildForDevelopment()
,buildForProduction()
const cssConfig = filter: '' path: extraResources: path path fileName: '' prefixWrap: '';example
cssConfig
:filter (option)
: This can set the SCSS loader should'include'
or'exclude'
the path below during the bundling.path (option)
: This is the path that you like to include/exclude in the SCSS loader.extraResources (option)
: The extra resource that you like to include when you are bundling the SCSS.prefixWrap (option)
: This is the option that can enable postcss-prefixwrap. If you don't want to enable this function, please do not provide it as parameter.fileName (option)
: The file name of the css file when it be extracted in the production mode. If you leave it blank, it will become the name of your entry point (js).fastLoader (option)
: Switching from sass-loader to fast-sass-loader. (Enable this will stop supporting thesourcemap
andextraResource
from sass-loader).
7. addConfig()
: Add any additional settings into the configuration.
Execute this function before execute
buildForDevServer()
,buildForDevelopment()
,buildForProduction()
const extraConfig = plugins: $: 'jquery' ;example;
Extra
Some other function that can generate the configuration that can be add in addConfig()
-
webpack2-general-config.Style
:Style.extractSCSStoCSS({env = 'production', filter = '', path = [], extraResources = [], fileName = '', prefixWrap='', fastLoader = false})
Style.inlineSCSStoCSS({env = 'development', filter = '', path=[], extraResources = [], prefixWrap='', fastLoader = false})
Style.SCSStoCSSModule({ env = 'development', filter = '', path = [], extraResources = [], sassResource = [], fileName = '', fastLoader = false })
Style.addSprite({srcFolder, srcType = '*.png', targetImgFolder, targetSCSSFolder, cssImageRef})
:Style
-
webpack2-general-config.Util
:Util.devServer({ host = 'localhost', port = 8100 })
Util.optimize()
Util.setEnvironmentVariable(variables)
Util.clean (path)
Util.providePlugin(provide)
-
webpack2-general-config.Lint
:Lint.eslint(path, filter = "exclude")
Lint.sassLint(path)