Last active
March 11, 2017 16:38
-
-
Save slavama/3b5b273cc0a564712d3033540f805b49 to your computer and use it in GitHub Desktop.
My webpack config
This file contains 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
module.exports = { | |
"env": { | |
"browser": true, | |
"commonjs": true, | |
"es6": true, | |
"node": true, | |
}, | |
"extends": "eslint:recommended", | |
"parserOptions": { | |
"sourceType": "module", | |
}, | |
"rules": { | |
"comma-dangle": ["error", "always-multiline"], | |
"indent": ["error", 4], | |
"linebreak-style": ["error", "unix"], | |
"quotes": ["error", "single"], | |
"semi": ["error", "always"], | |
"no-unused-vars": ["warn"], | |
"no-console": 0, | |
}, | |
}; |
This file contains 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
{ | |
"name": "static", | |
"version": "0.1.0", | |
"description": "New project", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1", | |
"lint:js": "eslint . --cache" | |
}, | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"babel": "^6.23.0", | |
"babel-core": "^6.23.1", | |
"babel-loader": "^6.4.0", | |
"babel-preset-es2015": "^6.22.0", | |
"css-loader": "^0.27.0", | |
"eslint": "^3.17.1", | |
"eslint-loader": "^1.6.3", | |
"extract-text-webpack-plugin": "^2.1.0", | |
"file-loader": "^0.10.1", | |
"less": "^2.7.2", | |
"less-loader": "^3.0.0", | |
"style-loader": "^0.13.2", | |
"url-loader": "^0.5.8", | |
"webpack": "^2.2.1", | |
"webpack-dev-server": "^2.4.1" | |
}, | |
"dependencies": { | |
"bootstrap": "^3.3.7", | |
"font-awesome": "^4.7.0", | |
"jquery": "^1.12.4", | |
"jquery-form": "^4.1.0", | |
"jquery-validation": "^1.16.0", | |
"jquery.cookie": "^1.4.1" | |
} | |
} |
This file contains 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
onst path = require('path'); | |
const webpack = require('webpack'); | |
const ExtractTextPlugin = require("extract-text-webpack-plugin"); | |
const vendorCSS = new ExtractTextPlugin('css/vendors.css'); | |
const mainCSS = new ExtractTextPlugin('css/main.css'); | |
function isExternal(module) { | |
const userRequest = module.userRequest; | |
if (typeof userRequest !== 'string') { | |
return false; | |
} | |
return userRequest.indexOf('bower_components') >= 0 || | |
userRequest.indexOf('node_modules') >= 0 || | |
userRequest.indexOf('lib') >= 0; | |
} | |
module.exports = { | |
devtool: 'source-map', | |
entry: { | |
main: "./js/index.js" | |
}, | |
output: { | |
path: path.resolve(__dirname, 'dist'), | |
filename: 'js/[name].js' | |
}, | |
module: { | |
rules: [ | |
{ | |
enforce: "pre", | |
test: /\.(js|jsx)$/, | |
exclude: /node_modules/, | |
loader: "eslint-loader" | |
}, | |
{ | |
test: /\.(js|jsx)$/, | |
loader: 'babel-loader', | |
exclude: /(node_modules|bower_components)/, | |
options: { | |
presets: ['es2015'], | |
sourceMap: true | |
} | |
}, | |
{ | |
test: /\.css$/, | |
use: vendorCSS.extract({ | |
use: { | |
loader: 'css-loader', | |
options: { | |
minimize: {discardComments: {removeAll: true}} | |
} | |
} | |
}), | |
}, | |
{ | |
test: /\.less$/, | |
use: mainCSS.extract({ | |
fallback: 'style-loader', | |
use: [ | |
{ | |
loader: 'css-loader', | |
options: { | |
minimize: {discardComments: {removeAll: true}}, | |
sourceMap: true | |
} | |
}, | |
'less-loader' | |
], | |
}) | |
}, | |
{ | |
test: /\.(woff2?|ttf|eot|svg|gif|png|jpg|jpeg)$/, | |
use: 'file-loader?name=[name].[ext]&publicPath=../media/&outputPath=media/' | |
} | |
] | |
}, | |
plugins: [ | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: 'vendors', | |
minChunks: function (module) { | |
return isExternal(module); | |
} | |
}), | |
new webpack.ProvidePlugin({ | |
jQuery: 'jquery', | |
$: 'jquery', | |
jquery: 'jquery' | |
}), | |
vendorCSS, | |
mainCSS, | |
new webpack.optimize.UglifyJsPlugin({ | |
compress: {warnings: false}, | |
output: {comments: false}, | |
sourceMap: true | |
}) | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment