Skip to content

Instantly share code, notes, and snippets.

@treetrum
Created October 10, 2018 06:28
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 treetrum/c30cb716a89b4806992169cbc259e646 to your computer and use it in GitHub Desktop.
Save treetrum/c30cb716a89b4806992169cbc259e646 to your computer and use it in GitHub Desktop.
Twig Webpack Copy/Compile
const Path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const Twig = require('twig');
module.exports = {
mode: 'development',
entry: './src/app.js',
output: {
path: Path.join(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new CopyWebpackPlugin([
{
from: './src/index.twig',
to: 'index.html',
transform(content, path) {
return new Promise(resolve => {
Twig.renderFile(path, {}, (err, html) => {
if (err) {
console.error('Did not compile Twig Template at path:', path);
}
resolve(html);
});
});
}
}
])
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment