Skip to content

Instantly share code, notes, and snippets.

@falendary
Created May 3, 2017 09:12
Show Gist options
  • Save falendary/1e32492018e25a811b61709debf9fa28 to your computer and use it in GitHub Desktop.
Save falendary/1e32492018e25a811b61709debf9fa28 to your computer and use it in GitHub Desktop.
webpack.config.js
var webpack = require('webpack');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var CleanWebpackPlugin = require('clean-webpack-plugin');
const ENV = process.env.NODE_ENV.trim();
console.log('ENV: ' + ENV);
const extractLess = new ExtractTextPlugin({
filename: function () {
if (ENV === 'production') {
return '/portal/content/css/main.min.css';
} else {
return '/portal/content/css/main.css';
}
}
//disable: process.env.ENV === 'development'
});
const extractHtml = new HtmlWebpackPlugin({
template: 'src/index.html'
});
const cleanDist = new CleanWebpackPlugin(['dist/portal']);
var config = {
//context: path.resolve(__dirname, './app'),
entry: [path.resolve(__dirname, 'src/portal/scripts/main.js')],
resolve: {
alias: {}
},
output: {
path: path.resolve(__dirname, 'dist/'),
//publicPath: path.resolve(__dirname, 'dist/'),
filename: 'portal/scripts/main.min.js'
},
module: {
loaders: [
{
test: /\.html$/,
use: [
{
loader: 'html-loader',
options: {
minimize: ENV === 'production'
}
}
]
},
{
test: /\.less$/,
use: extractLess.extract({
use: [{
loader: 'css-loader',
options: {
minimize: ENV === 'production'
}
}, {
loader: 'less-loader'
}],
fallback: 'style-loader' // use style-loader in development
})
},
{
test: /\.(jpe?g|png|gif|svg)$/,
exclude: /node_modules/,
use: [
{
loader: 'file-loader',
options: {
useRelativePath: true,
name: '[name].[ext]',
context: 'portal/content/img',
outputPath: 'portal/content/img/'
}
//'image-webpack?progressive=true&optimizationLevel=7&interlaced=true'
}
]
},
{
test: /\.json$/,
exclude: /node_modules/,
use: [
'file-loader?name=[name].[ext]&outputPath=portal/content/json'
]
},
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
exclude: /node_modules/,
use: [
'url-loader?limit=1024&name=portal/content/fonts/[name].[ext]'
]
}
]
//noParse: []
},
externals: {
angular: 'angular',
$: 'jQuery'
},
plugins: [
//cleanDist,
extractLess,
extractHtml
//htmlLoader
],
devtool: 'source-map'
};
module.exports = config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment