Last active
June 18, 2016 08:51
-
-
Save DragorWW/1e4e541bf85d9b5c1e945428dbee0f69 to your computer and use it in GitHub Desktop.
webpack base config
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
| var ISDEV = 'development' === process.env.NODE_ENV; | |
| var path = require('path'); | |
| var webpack = require('webpack'); | |
| var autoprefixer = require('autoprefixer'); | |
| var ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
| var SvgStore = require('webpack-svgstore-plugin'); | |
| var CleanWebpackPlugin = require('clean-webpack-plugin'); | |
| var pathList = { | |
| source: path.join(__dirname, 'app'), | |
| build: path.join(__dirname, 'www/build') | |
| } | |
| module.exports = { | |
| context: pathList.source, | |
| entry: { | |
| main: './main', | |
| login: './login', | |
| common: './common' | |
| }, | |
| output: { | |
| path: pathList.build, | |
| filename: '[name].min.js', | |
| publicPath: '/build/' | |
| }, | |
| module: { | |
| loaders: [ | |
| { | |
| test: /\.less$/, | |
| loader: ExtractTextPlugin.extract('style', function () { | |
| return ISDEV? 'css!postcss!less' : 'css?minimize!postcss!less'; | |
| }()) | |
| }, | |
| { | |
| test: /\.es6$/, | |
| exclude: /node_modules/, | |
| loader: 'babel', | |
| query: { | |
| presets: [ | |
| 'es2015' | |
| ] | |
| } | |
| }, | |
| { | |
| test: /\.(ttf|eot|woff(2)?)(\?[a-z0-9]+)?$/, | |
| loader: 'file-loader?name=fonts/[hash].[ext]' | |
| }, | |
| { | |
| test: /\.(jpe?g|png|gif|svg)$/i, | |
| loaders: [ | |
| 'url?limit=5000&name=images/[hash].[ext]', | |
| 'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false' | |
| ] | |
| } | |
| ] | |
| }, | |
| devtool: ISDEV? 'inline-source-map' : null, | |
| watch: ISDEV, | |
| watchOptions: { | |
| aggregateTimeout: 100 | |
| }, | |
| resolve: { | |
| alias: { | |
| jquery: 'jquery/dist/jquery.js', | |
| $: 'jquery' | |
| }, | |
| root: pathList.source, | |
| extensions: ['', '.js', '.es6'] | |
| }, | |
| plugins: [ | |
| new webpack.ProvidePlugin({ | |
| $: 'jquery', | |
| jQuery: 'jquery', | |
| 'window.jQuery': 'jquery' | |
| }), | |
| new ExtractTextPlugin('[name].css', { | |
| allChunks: true | |
| }), | |
| new webpack.optimize.CommonsChunkPlugin('common', 'common.min.js'), | |
| new SvgStore(path.join(__dirname, 'app', '**', '*.svg'), path.join('images', 'svg'), { | |
| name: 'sprite.svg', | |
| prefix: '', | |
| svgOptions: { | |
| // options for svgo | |
| plugins: [ | |
| { | |
| removeTitle: true, | |
| sortAttrs: true | |
| }, | |
| ] | |
| } | |
| }) | |
| ], | |
| postcss: function () { | |
| return [ | |
| autoprefixer({browsers: ['last 3 versions', 'ie >= 9']}) | |
| ]; | |
| } | |
| }; | |
| if (!ISDEV) { | |
| module.exports.bail = true; | |
| module.exports.plugins.push(new CleanWebpackPlugin(['build'], { | |
| root: path.join(__dirname, 'www'), | |
| verbose: true, | |
| dry: false | |
| })); | |
| module.exports.plugins.push(new webpack.optimize.OccurrenceOrderPlugin()); | |
| module.exports.plugins.push(new webpack.optimize.UglifyJsPlugin({ | |
| sourceMap: false, | |
| compress: { | |
| warnings: false | |
| } | |
| })); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment