Created
May 3, 2017 09:12
-
-
Save falendary/1e32492018e25a811b61709debf9fa28 to your computer and use it in GitHub Desktop.
webpack.config.js
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 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