// Required Components
// ==========================================================================
const ev = require('../export-vars.js');
const path = require('path');
const merge = require('webpack-merge');
const common = require('../webpack/webpack.common.js');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const dv = require('./district-vars.js');
const webpackDistrictDeploy = merge(common, {
entry: dv.entryPROD,
devtool: 'none',
watch: true,
watchOptions: {
ignored: [
/node_modules/,
"../src/**/**/**/**",
]
},
performance: {
hints: "warning",
maxEntrypointSize: 500000,
maxAssetSize: 300000
},
plugins: [
new ev.UglifyJsPlugin({
extractComments: true
}),
new ev.wp.optimize.CommonsChunkPlugin({
children: true,
}),
new BrowserSyncPlugin({
host: 'localhost',
port: 5000,
proxy: ev.pkg.config.siteurl + '/' + ev.pkg.config.startpage,
notify: false,
// files: [
// ev.directory + 'main.css',
// ],
}, {
reload: true,
}),
],
module: {
rules: [
{
test: /\.scss$/,
use: ev.ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{ loader: 'css-loader'},
{ loader: 'postcss-loader',
options: {
plugins: [
require('cssnano')({
preset: [
'default',
{ discardComments: { removeAll: true } }
],
}),
],
minimize: true
},
},
{ loader: 'resolve-url-loader'},
{ loader: 'sass-loader',
options: {
sourceMap: true,
outputStyle: 'compact',
data: '@import "include";',
includePaths: [
path.resolve(__dirname, '../src/sass/')
]
}
}
]
})
}
],
},
output: {
path: ev.directory,
filename: '[name].js'
}
});
module.exports = webpackDistrictDeploy;
This is school1.js
which is the basis of what loads in for “sub sites”
require("../sass/school1.scss");
require("../../build.js");
require("./all.js");
And this is build.js
// require main build files
require('./sass/main.scss');
require('./js/global.js');
//components
require('./components/test/index.js');
The problem I have is Sass related; school1.scss and build.js both import something called main.scss
. school1.scss
imports main.scss and then I update color variables, and that’s the purpose of that.
The problem is that build.js
also imports main.scss
. I know conditional requires aren’t really a thing in webpack. I tried to conditionally require main.scss only if “sub sites” are turned on. But it was bundling it anyway.
Is there anything I can do here? Some way to only load in main.scss once? The problem is that I’m importing it twice so my file sizes are twice as big.
I tried changing this up to add in build.js (first value in the array) but I ended up removing it because the color Sass variables weren’t updating. I think I have to keep this as just [PATHS[name]];
exports.entryPROD[name] = [path.join(__dirname, "../src/build.js"), PATHS[name]];