Skip to content

Instantly share code, notes, and snippets.

@jonathan-s
Created May 10, 2020 12:16
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 jonathan-s/ac95da6e1e2f8b4ce3961e6a6e7ea30d to your computer and use it in GitHub Desktop.
Save jonathan-s/ac95da6e1e2f8b4ce3961e6a6e7ea30d to your computer and use it in GitHub Desktop.
Webpack configuration that could be used as a starting point.
const webpack = require('webpack');
const glob = require('glob');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
// npm install needed
// css-loader postcss-loader postcss-import tailwindcss autoprefixer mini-css-extract-plugin glob
let globOptions = {
ignore: [
'./node_modules/**',
'./venv/**',
'./django-sockpuppet/**',
'./dist/**'
]
}
let entryFiles = glob.sync("./**/javascript/*.js", globOptions)
let entryObj = {};
entryFiles.forEach(function(file){
if (file.includes('.')) {
let parts = file.split('/')
let path = parts.pop()
let fileName = path.split('.')[0];
entryObj[fileName] = `${file}`;
}
});
// entry points for css. Look for all css files in project.
entryObj['style'] = glob.sync("./**/*.css", globOptions)
console.log(entryObj)
let cssRules = {
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer')
]
}
}
]
}
module.exports = function(env, argv) {
let config = {
mode: process.env.NODE_ENV,
entry: entryObj,
output: {
path: __dirname + '/dist/',
filename: 'js/[name].js'
},
optimization: {
minimize: false
},
plugins: [
// extracting any css into its own file.
// the loader is also needed for css.
new MiniCssExtractPlugin({
filename: "css/[name].css",
})
],
module: {
rules: [
cssRules,
]
},
}
return config
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment