Created
April 27, 2016 13:07
-
-
Save smorcuend/e2f456b3b1b31b6fd3398776e2cc6dba to your computer and use it in GitHub Desktop.
basic config for webpack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
/* | |
* Webpack Plugins | |
*/ | |
// const webpack = require('webpack'); | |
// const CopyWebpackPlugin = require('copy-webpack-plugin'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
module.exports = { | |
/* | |
* Cache generated modules and chunks to improve performance for multiple incremental builds. | |
* This is enabled by default in watch mode. | |
* You can pass false to disable it. | |
* | |
* See: http://webpack.github.io/docs/configuration.html#cache | |
* cache: false, | |
* | |
* The entry point for the bundle | |
* Our Angular.js app | |
* | |
* See: http://webpack.github.io/docs/configuration.html#entry | |
*/ | |
entry: [ | |
// 'webpack-hot-middleware/client?path=http://localhost:8888/__webpack_hmr', | |
'webpack-dev-server/client?http://localhost:8888/', | |
'./src/js/index.js' | |
], | |
/* | |
* Options affecting the resolving of modules. | |
* | |
* See: http://webpack.github.io/docs/configuration.html#resolve | |
*/ | |
resolve: { | |
/* | |
* An array of extensions that should be used to resolve modules. | |
* | |
* See: http://webpack.github.io/docs/configuration.html#resolve-extensions | |
*/ | |
extensions: ['', '.js'], | |
// Make sure root is src | |
// root: helpers.root('src'), | |
// remove other default values | |
modulesDirectories: ['node_modules'] | |
}, | |
/* | |
* Options affecting the normal modules. | |
* | |
* See: http://webpack.github.io/docs/configuration.html#module | |
*/ | |
module: { | |
/* | |
* An array of applied pre and post loaders. | |
* | |
* See: http://webpack.github.io/docs/configuration.html#module-preloaders-module-postloaders | |
*/ | |
// preLoaders: [{ | |
// test: /\.js$/, | |
// loader: 'eslint', | |
// exclude: /node_modules/ | |
// }], | |
/* | |
* An array of automatically applied loaders. | |
* | |
* IMPORTANT: The loaders here are resolved relative to the resource which they are applied to. | |
* This means they are not resolved relative to the configuration file. | |
* | |
* See: http://webpack.github.io/docs/configuration.html#module-loaders | |
*/ | |
loaders: [ | |
{ | |
test: /\.js$/, | |
loader: 'babel-loader', | |
query: { | |
presets: ['es2015'] | |
}, | |
exclude: /node_modules/ | |
}, | |
/* | |
* Json loader support for *.json files. | |
* | |
* See: https://github.com/webpack/json-loader | |
*/ | |
{ | |
test: /\.json$/, | |
loader: 'json-loader' | |
}, | |
/* | |
* Raw loader support for *.css files | |
* Returns file content as string | |
* | |
* See: https://github.com/webpack/raw-loader | |
*/ | |
// { | |
// test: /\.css$/, | |
// loader: 'raw!style!css' | |
// }, | |
// Extract css files | |
{ | |
test: /\.css$/, | |
loader: ExtractTextPlugin.extract(['style', 'css']), | |
include: path.join(__dirname, '../src/styles/index.css') | |
}, { | |
test: /\.sass$/, | |
loader: ExtractTextPlugin.extract('style-loader', 'css-loader', 'sass-loader') | |
}, { | |
test: /\.less$/, | |
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!less-loader') | |
}, { | |
test: /.(png|woff(2)?|eot|ttf|svg)(\?[a-z0-9=\.]+)?$/, | |
loader: 'url-loader?limit=100000' | |
} | |
] | |
}, | |
plugins: [ | |
/* | |
* Plugin: HtmlWebpackPlugin | |
* Description: Simplifies creation of HTML files to serve your webpack bundles. | |
* This is especially useful for webpack bundles that include a hash in the filename | |
* which changes every compilation. | |
* | |
* See: https://github.com/ampedandwired/html-webpack-plugin | |
*/ | |
new HtmlWebpackPlugin({ | |
template: 'src/index.html' | |
}), | |
new ExtractTextPlugin('style.css') | |
], | |
/* | |
* Include polyfills or mocks for various node stuff | |
* Description: Node configuration | |
* | |
* See: https://webpack.github.io/docs/configuration.html#node | |
*/ | |
node: { | |
global: 'window', | |
crypto: 'empty', | |
module: false, | |
clearImmediate: false, | |
setImmediate: false | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const webpack = require('webpack'); // used to merge webpack configs | |
const webpackMerge = require('webpack-merge'); // used to merge webpack configs | |
const baseConfig = require('./webpack.base'); | |
const METADATA = { | |
host: 'localhost', | |
port: 8888, | |
outputPath: path.resolve(__dirname, '../src') | |
}; | |
/** | |
* Webpack configuration | |
* | |
* See: http://webpack.github.io/docs/configuration.html#cli | |
*/ | |
module.exports = webpackMerge(baseConfig, { | |
/** | |
* Switch loaders to debug mode. | |
* | |
* See: http://webpack.github.io/docs/configuration.html#debug | |
*/ | |
debug: true, | |
/** | |
* Developer tool to enhance debugging | |
* | |
* See: http://webpack.github.io/docs/configuration.html#devtool | |
* See: https://github.com/webpack/docs/wiki/build-performance#sourcemaps | |
*/ | |
// devtool: 'cheap-module-eval-source-map', | |
devtool: 'source-map', | |
/** | |
* Options affecting the output of the compilation. | |
* | |
* See: http://webpack.github.io/docs/configuration.html#output | |
*/ | |
output: { | |
/** | |
* The output directory as absolute path (required). | |
* | |
* See: http://webpack.github.io/docs/configuration.html#output-path | |
*/ | |
path: METADATA.outputPath, | |
/** | |
* Specifies the name of each output file on disk. | |
* IMPORTANT: You must not specify an absolute path here! | |
* | |
* See: http://webpack.github.io/docs/configuration.html#output-filename | |
*/ | |
filename: 'index.build.js', | |
/** | |
* The filename of the SourceMaps for the JavaScript files. | |
* They are inside the output.path directory. | |
* | |
* See: http://webpack.github.io/docs/configuration.html#output-sourcemapfilename | |
*/ | |
sourceMapFilename: '[name].map', | |
/** The filename of non-entry chunks as relative path | |
* inside the output.path directory. | |
* | |
* See: http://webpack.github.io/docs/configuration.html#output-chunkfilename | |
*/ | |
chunkFilename: '[id].chunk.js' | |
}, | |
plugins: [ | |
new webpack.optimize.OccurenceOrderPlugin(true), | |
new webpack.NoErrorsPlugin() | |
], | |
/** | |
* Webpack Development Server configuration | |
* Description: The webpack-dev-server is a little node.js Express server. | |
* The server emits information about the compilation state to the client, | |
* which reacts to those events. | |
* | |
* See: https://webpack.github.io/docs/webpack-dev-server.html | |
*/ | |
devServer: { | |
port: METADATA.port, | |
host: METADATA.host, | |
hot: true, | |
inline: true, | |
historyApiFallback: true, | |
colors: true, | |
stats: 'normal', | |
progress: true, | |
open: true, | |
watchOptions: { | |
aggregateTimeout: 300, | |
poll: 1000 | |
}, | |
outputPath: METADATA.outputPath, | |
contentBase: 'src/' | |
} | |
}, baseConfig); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Empty |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment