Created
November 29, 2018 07:19
-
-
Save gpbeer/5f689627cf42e71a7c92ac7e1735446c to your computer and use it in GitHub Desktop.
Multisite webpack
This file contains hidden or 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
{ | |
"name": "multisite", | |
"copyright": "2018", | |
"version": "1.0.0", | |
"dependencies": { | |
"bootstrap-sass": "^3.3.7", | |
"jquery": "^2.1.3", | |
"wp-admin-custom": "4.9.6" | |
}, | |
"devDependencies": { | |
"babel-core": "^6.26.0", | |
"babel-loader": "^7.1.2", | |
"babel-preset-es2015": "^6.24.1", | |
"browser-sync": "^2.23.6", | |
"browser-sync-webpack-plugin": "^1.2.0", | |
"css-loader": "^0.28.7", | |
"extract-text-webpack-plugin": "^3.0.0", | |
"file-loader": "^0.11.2", | |
"node-sass": "^4.5.3", | |
"path": "^0.12.7", | |
"sass-loader": "^6.0.6", | |
"style-loader": "^0.18.2", | |
"webpack": "^3.10.0" | |
}, | |
"scripts": { | |
"build": "webpack --progress --env.production -p", | |
"watch": "webpack --progress --env.dev --display=minimal --colors --watch" | |
}, | |
"repository": { | |
"type": "git" | |
}, | |
"author": "German Pichardo", | |
"license": "UNLICENSED", | |
"private": true | |
} |
This file contains hidden or 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
'use strict'; | |
const webpack = require('webpack'); | |
const path = require('path'); | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const BrowserSyncPlugin = require('browser-sync-webpack-plugin'); | |
const themesPath = path.join(__dirname, 'web/app/themes'); | |
const themeAssets = { | |
'base': path.join(themesPath, 'base/assets'), | |
'theme_1': path.join(themesPath, 'theme_1/assets'), | |
'theme_2': path.join(themesPath, 'theme-2/assets'), | |
'theme_3': path.join(themesPath, 'theme-2/assets'), | |
}; | |
// https://stackoverflow.com/a/45278943 | |
module.exports = function (env, argv) { | |
return { | |
devtool: env.production ? '' : 'inline-source-map', | |
entry: { | |
'web/app/themes/theme-1/assets/build/theme': [ | |
path.join(themeAssets.theme_1, 'js/theme.js'), | |
path.join(themeAssets.theme_1, 'scss/theme.scss'), | |
], | |
'web/app/themes/theme-2/assets/build/theme': [ | |
path.join(themeAssets.theme_2, 'js/theme.js'), | |
path.join(themeAssets.theme_2, 'scss/theme.scss'), | |
], | |
'web/app/themes/theme-3/assets/build/theme': [ | |
path.join(themeAssets.theme_3, 'js/theme.js'), | |
path.join(themeAssets.theme_3, 'scss/theme.scss'), | |
], | |
}, | |
output: { | |
filename: '[name].js', | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.js/, | |
use: [ | |
{ | |
loader: 'babel-loader' | |
} | |
] | |
}, | |
{ | |
test: /\.scss$/, | |
use: ExtractTextPlugin.extract({ | |
fallback: 'style-loader', | |
use: [{ | |
loader: 'css-loader', | |
options: { | |
sourceMap: !env.production, | |
minimize: env.production | |
} | |
}, { | |
loader: 'sass-loader', | |
options: { | |
outputStyle: 'expanded', // Build bug (.class-white -> .class-#fff) | |
sourceMap: !env.production | |
} | |
}] | |
}) | |
}, | |
{ | |
test: /\.(png|jpg|gif|svg|eot|ttf|woff|woff2)$/, | |
loader: 'file-loader', | |
options: { | |
name: '[name].[ext]', | |
useRelativePath: true // TODO: No images treatment ?? | |
} | |
} | |
] | |
}, | |
externals: { | |
$: '$', | |
jquery: | |
'jQuery' | |
}, | |
plugins: [ | |
new webpack.optimize.UglifyJsPlugin({ | |
compress: argv['optimize-minimize'], // only if -p or --optimize-minimize were passed | |
sourceMap: !env.production | |
}), | |
new ExtractTextPlugin('[name].css'), | |
new BrowserSyncPlugin({ | |
// browse to http://localhost:3000/ during development, | |
// ./public directory is being served | |
proxy: http://localhost:3000/, | |
port: 8686, | |
files: [ | |
'**/*.twig' | |
], | |
reloadOnRestart: true | |
}, | |
// plugin options | |
{ | |
reload: true | |
}) | |
], | |
resolve: { | |
alias: { | |
'base-scss': path.join(themeAssets.base, 'scss'), // TODO verify path in prod | |
'base-js': path.join(themeAssets.base, 'js') | |
} | |
} | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment