Created
August 8, 2016 05:46
-
-
Save lavezzi1/1179d91c584c0b0a7544c862c8bb07ca to your computer and use it in GitHub Desktop.
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
var webpack = require("webpack"); | |
var path = require('path'); | |
var fs = require('fs'); | |
var HtmlwebpackPlugin = require('html-webpack-plugin'); | |
var CopyWebpackPlugin = require('copy-webpack-plugin'); | |
var ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
var containerPath = path.resolve('./'); | |
var compile = require('./bin/compile.js'); | |
var getEntry = require('./bin/getEntry.js'); | |
var alias = require('./bin/alias.js'); | |
var entrys = getEntry('./app/src/views/**/*.js'); | |
entrys.common = ['vue', 'vue-router', 'fastclick', 'vue-async-data', 'vue-resource']; | |
module.exports = { | |
entry: entrys, | |
output: { | |
path: path.resolve(containerPath, './app/www/'), | |
publicPath: './', | |
filename: '[name].js', | |
chunkFilename: '[name].[hash].js' | |
}, | |
resolve: { | |
alias: alias, | |
extensions: ['', '.js', '.vue', '.scss', '.css', '.png', '.jpg'], | |
}, | |
module: { | |
loaders: [ | |
{ | |
test: /\.vue$/, | |
loader: 'vue' | |
}, | |
{ | |
test: /\.js$/, | |
loader: 'babel', | |
exclude: /node_modules/ | |
}, | |
{ | |
test: /\.css$/, | |
loader: ExtractTextPlugin.extract('style-loader', 'css-loader?sourceMap') | |
}, | |
{ | |
test: /\.scss$/, | |
loader: ExtractTextPlugin.extract('style-loader','css-loader?sourceMap!sass-loader') | |
}, { | |
test: /\.(png|jpg|gif)$/, | |
loader: 'url-loader?limit=8192&name=images/[name].[ext]' | |
}, { | |
test: /\.json$/, | |
loader: 'json' | |
}, { | |
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, | |
loader: "file-loader" | |
}, { | |
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, | |
loader: "url-loader?limit=10000&minetype=application/font-woff" | |
}, | |
] | |
}, | |
babel: { | |
presets: ["es2015", "stage-0"], | |
"plugins": ["transform-runtime", ["component", [{ | |
"libraryName": "mint-ui", | |
"style": true | |
}]]] | |
}, | |
vue: { | |
loaders: { | |
css: ExtractTextPlugin.extract("vue-style-loader", "css-loader?sourceMap"), | |
scss: ExtractTextPlugin.extract("vue-style-loader", "css-loader?sourceMap", "sass-loader") | |
}, | |
autoprefixer: { | |
browsers: ['last 2 versions'] | |
}, | |
postcss: [ | |
require('postcss-nested')(), | |
require('postcss-partial-import')({ | |
addDependencyTo: webpack | |
}), | |
require('lost') | |
] | |
}, | |
plugins: [ | |
new ExtractTextPlugin('[name].css', { | |
allChunks: true | |
}), | |
new webpack.optimize.CommonsChunkPlugin('common', 'common.js') | |
] | |
}; | |
// Detect environment | |
var prod = process.env.NODE_ENV === 'production'; | |
console.log(prod); | |
module.exports.plugins = (module.exports.plugins || []); | |
if (prod) { | |
module.exports.devtool = 'source-map'; | |
module.exports.plugins = module.exports.plugins.concat([ | |
new webpack.DefinePlugin({ | |
'process.env': { | |
NODE_ENV: '"production"' | |
} | |
}), | |
new webpack.optimize.UglifyJsPlugin({ | |
compress: { | |
warnings: false | |
} | |
}), | |
new webpack.optimize.OccurenceOrderPlugin(), | |
new webpack.NoErrorsPlugin(), | |
new webpack.BannerPlugin('vue') | |
]); | |
} else { | |
module.exports.devtool = 'eval-source-map'; | |
} | |
// html process | |
var pages = getEntry('./app/src/views/**/*.html'); | |
for (var chunkname in pages) { | |
var conf = { | |
filename: chunkname + '.html', | |
template: pages[chunkname], | |
inject: true, | |
minify: { | |
removeComments: true, | |
collapseWhitespace: false | |
}, | |
chunks: ['common', chunkname], | |
hash: true, | |
} | |
module.exports.plugins.push(new HtmlwebpackPlugin(conf)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment