Skip to content

Instantly share code, notes, and snippets.

@lavezzi1
Created August 8, 2016 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lavezzi1/57a137661052baf1f111761f8943bfa9 to your computer and use it in GitHub Desktop.
Save lavezzi1/57a137661052baf1f111761f8943bfa9 to your computer and use it in GitHub Desktop.
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!postcss-loader?sourceMap')
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style-loader','css-loader!postcss-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!postcss-loader?sourceMap"),
scss: ExtractTextPlugin.extract("vue-style-loader", "css-loader!postcss-loader?sourceMap", "sass-loader")
},
// autoprefixer: {
// browsers: ['last 2 versions']
// },
postcss: [
require('postcss-nested')(),
require('postcss-import')({
addDependencyTo: webpack
}),
require('postcss-cssnext')(),
require('lost')
]
},
plugins: [
new ExtractTextPlugin('[name].css', {
allChunks: false
}),
new webpack.optimize.CommonsChunkPlugin('common', 'common.js')
]
};
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