Created
May 10, 2020 12:16
-
-
Save jonathan-s/ac95da6e1e2f8b4ce3961e6a6e7ea30d to your computer and use it in GitHub Desktop.
Webpack configuration that could be used as a starting point.
This file contains 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
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