Skip to content

Instantly share code, notes, and snippets.

@omargourari
Last active March 21, 2018 09:44
Show Gist options
  • Save omargourari/dc2583a79d4dbcadc39a8e8026f1961a to your computer and use it in GitHub Desktop.
Save omargourari/dc2583a79d4dbcadc39a8e8026f1961a to your computer and use it in GitHub Desktop.
Webpack configuration for IntlTelInput issue
const path = require('path')
const utils = require('./build/utils')
const webpack = require('webpack')
const autoprefixer = require('autoprefixer')
const precss = require('precss')
const BundleTracker = require('webpack-bundle-tracker')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
// const HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
var vueLoaderConfig = require('./build/vue-loader.conf')
function resolve(dir) {
return path.join(__dirname, '..', dir)
}
// the path(s) that should be cleaned
const pathsToClean = ['./onboarding/static/onboarding/bundles', './wm_private_area/static/wm_private_area/bundles']
// the clean options to use
const cleanOptions = {
root: path.resolve('../apps/'),
verbose: true,
dry: false
}
const commonPlugins = [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.HotModuleReplacementPlugin(),
// new Jarvis({ port: 1337 }),
new webpack.ProvidePlugin({
$: 'jquery',
jquery: 'jquery',
'window.jQuery': 'jquery',
jQuery: 'jquery',
_: 'lodash',
Popper: ['popper.js', 'default'],
Tether: 'tether',
'window.Tether': 'tether',
utils: 'utils'
}),
new CleanWebpackPlugin(pathsToClean, cleanOptions),
new ExtractTextPlugin('./src/containers/**/*', './src/components/**/*'),
// new HardSourceWebpackPlugin(),
new BundleTracker({filename: './webpack-stats.json'}),
new CopyWebpackPlugin([
{
from: './node_modules/amcharts3/amcharts/images',
to: 'amcharts/images'
}
])
]
const commonModulesLoaders = {
rules: [
{
test: /\.(js|vue)$/,
loader: 'eslint-loader',
enforce: 'pre',
include: [resolve('src')],
options: {
formatter: require('eslint-friendly-formatter')
}
},
{
test: /\.vue$/,
loader: 'vue-loader',
options: vueLoaderConfig
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [path.join('./', 'node_modules')],
exclude: /(bower_components)/,
query: {
cacheDirectory: true,
presets: ['es2015', 'flow', 'stage-3', 'stage-2'],
plugins: [
'transform-runtime',
'babel-plugin-transform-class-properties',
'babel-plugin-syntax-flow',
'babel-plugin-transform-flow-strip-types',
'syntax-dynamic-import',
'transform-object-rest-spread',
'transform-es2015-destructuring',
'transform-es2015-parameters'
],
comments: true
}
},
{
test: /\.(png|jpg|gif)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]',
publicPath: 'static/bundles/'
},
include: [path.join('./', 'node_modules')]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
query: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.svg$/,
oneOf: [
{
exclude: path.resolve(__dirname, 'theme/svg/css-icons/'),
use: 'svg-inline-loader'
},
{
include: path.resolve(__dirname, 'theme/images/svg/css-icons/'),
use: 'file-loader'
}
]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader', 'postcss-loader']
},
{
test: /\.(scss)$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader'
},
{
loader: 'postcss-loader',
options: {
plugins() {
return [precss, autoprefixer]
}
}
},
{
loader: 'sass-loader'
}
]
})
},
{
test: /\.woff2?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
use: 'url-loader?limit=10000'
},
{
test: /\.(ttf|eot|svg)(\?[\s\S]+)?$/,
use: 'file-loader'
},
{
test: /font-awesome\.config\.js/,
use: [{loader: 'style-loader'}, {loader: 'font-awesome-loader'}]
},
{
test: /bootstrap\/dist\/js\/umd\//,
use: 'imports-loader?jQuery=jquery'
}
]
}
const commonResolve = {
alias: {
vue$: 'vue/dist/vue.esm.js',
'@': resolve('src'),
jquery: 'jquery/dist/jquery.slim.js',
utils: resolve('./src/utils'),
img: path.resolve('./theme/images')
},
extensions: ['.js', '.vue', '.json'],
modules: [path.resolve('./node_modules')],
symlinks: true
}
const commonExternals = {
jquery: 'jQuery'
}
const privateAreaConfig = {
context: __dirname,
entry: {
privateArea: ['./src/views/PrivateArea/PrivateArea.js'],
fontAwesome: ['font-awesome/scss/font-awesome.scss'],
Tether: ['tether/dist/js/tether.min.js']
},
devtool: '#cheap-module-eval-source-map',
output: {
path: path.resolve('../apps/wm_private_area/static/wm_private_area/bundles'),
filename: '[name].[hash].js'
},
plugins: commonPlugins,
module: commonModulesLoaders,
resolve: commonResolve,
externals: commonExternals
}
const onboardingConfig = {
context: __dirname,
entry: {
onboarding: ['./src/views/Onboarding/Onboarding.js']
},
devtool: '#cheap-module-eval-source-map',
output: {
path: path.resolve('../apps/onboarding/static/onboarding/bundles'),
filename: '[name].[hash].js'
},
plugins: commonPlugins,
module: commonModulesLoaders,
resolve: commonResolve
}
module.exports = [onboardingConfig, privateAreaConfig]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment