Skip to content

Instantly share code, notes, and snippets.

@meg-codes
Created January 11, 2019 16:07
Show Gist options
  • Save meg-codes/eaea30959f1cdf99359f70b341326a77 to your computer and use it in GitHub Desktop.
Save meg-codes/eaea30959f1cdf99359f70b341326a77 to your computer and use it in GitHub Desktop.
// path and webpack
const path = require('path')
const webpack = require('webpack')
// webpack plugins
const BundleTracker = require('webpack-bundle-tracker')
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
// configure dev mode because of absurdly misleading webpack documentation
module.exports = {
entry: {
'index': './sitemedia/js/index.js',
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'js/[name]-[hash].js'
},
module: {
rules: [
{
test: /\.css$/,
use: [
'vue-style-loader',
'css-loader',
'postcss-loader'
]
},
{
test: /\.scss$/,
use: [
process.env.NODE_ENV !== 'production' ? 'vue-style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
],
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: {
loaders: {
// Since sass-loader (weirdly) has SCSS as its default parse mode, we map
// the "scss" and "sass" values for the lang attribute to the right configs here.
// other preprocessors should work out of the box, no loader config like this necessary.
'scss': [
'vue-style-loader',
'css-loader',
'sass-loader'
]
}
// other vue-loader options go here
}
},
{
test: /^(?!.*\.spec\.js$).*\.js$/,
use:
process.env.NODE_ENV === 'development' ?
[
{loader: 'istanbul-instrumenter-loader', options: { esModules: true }},
'babel-loader'
]
: ['babel-loader'],
exclude: /node_modules/
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'file-loader',
options: {
name: '[name].[hash].[ext]',
}
}
]
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
},
extensions: ['*', '.js', '.vue', '.json']
},
devServer: {
contentBase: path.join(__dirname, 'sitemedia'),
hot: true,
compress: true,
port: 3000,
allowedHosts: ['localhost'],
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization'
},
historyApiFallback: true,
noInfo: true,
overlay: true
},
performance: {
hints: false
},
plugins: [
new BundleTracker({filename: './webpack-stats.json'}),
new VueLoaderPlugin(),
new MiniCssExtractPlugin({
filename: 'css/[name]-[hash].css'
})
]
}
if (process.env.NODE_ENV !== 'production') {
module.exports.mode = process.env.NODE_ENV
module.exports.output.publicPath = 'http://localhost:3000/'
module.exports.devtool = '#eval-source-map'
} else {
module.exports.output.publicPath = '/static/'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment