Skip to content

Instantly share code, notes, and snippets.

@pwaldhauer
Created November 12, 2017 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwaldhauer/2ef9b9164d64eb7d2bdc778ff29f7746 to your computer and use it in GitHub Desktop.
Save pwaldhauer/2ef9b9164d64eb7d2bdc778ff29f7746 to your computer and use it in GitHub Desktop.
const path = require('path');
const webpack = require('webpack');
const glob = require('glob');
const args = require('minimist')(process.argv.slice(2));
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const extractSass = new ExtractTextPlugin('css/[name].css', {
allChunks: true,
});
let env = 'dev';
if (args.env) {
env = args.env;
}
const base = {
entry: ['./source/js/main.js', './source/scss/main.scss'],
output: {
path: path.resolve('./assets/'),
filename: "js/[name].js",
},
resolve: {
modules: ['node_modules'],
alias: {
'vue$': 'vue/dist/vue.common.js'
}
},
plugins: [
extractSass,
new BrowserSyncPlugin(
{
host: 'localhost',
port: 3000,
proxy: 'http://0.0.0.0:19801/'
}
)
],
module: {
rules: [
{
test: /\.scss$/,
enforce: 'pre',
loader: 'import-glob-loader'
},
{
test: /\.js$/,
include: [
path.resolve(__dirname, "assets/js")
],
exclude: /(node_modules|bower_components)/,
use: [
{
loader: 'babel-loader',
query: {
presets: ['es2015'],
plugins: ['transform-es2015-shorthand-properties'],
cacheDirectory: true
}
}
],
},
{
test: /\.vue$/,
use: [
{
loader: 'vue-loader',
options: {
loaders: {
js: 'babel-loader'
}
}
}
]
},
{
test: /\.scss$/,
use: ExtractTextPlugin.extract({
use: ['css-loader', 'postcss-loader', 'sass-loader']
})
}
]
}
};
if (env === 'dev') {
base.devtool = "source-map";
base.devServer = {inline: true};
}
base.plugins.push(new webpack.optimize.CommonsChunkPlugin({
name: 'vendors',
}))
if (env === 'prod') {
base.plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}));
base.plugins.push(new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {warnings: false}
}));
base.plugins.push(new webpack.LoaderOptionsPlugin({
minimize: true
}));
}
module.exports = base;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment