Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It doesn't convert output to pug at all? #18

Open
techsin opened this issue Nov 10, 2018 · 3 comments
Open

It doesn't convert output to pug at all? #18

techsin opened this issue Nov 10, 2018 · 3 comments

Comments

@techsin
Copy link

techsin commented Nov 10, 2018

const webpack = require("webpack");
const path = require("path");
const glob = require("glob");
const PRODUCTION = process.env.NODE_ENV === "production";
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HtmlWebpackPugPlugin = require('html-webpack-pug-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');

const hotware = PRODUCTION ? [] : ["webpack/hot/dev-server", "webpack-hot-middleware/client"];
const entry = {};
let plugins = PRODUCTION
    ? [
        new webpack.DefinePlugin({
            "process.env": {
                NODE_ENV: JSON.stringify("production")
            }
        })
    ]
    : [new webpack.HotModuleReplacementPlugin()];

glob.sync("./frontend/scripts/*.js").forEach(function (fpath) {
    let filename = path.basename(fpath, path.extname(fpath));
    entry[filename] = [...hotware, fpath]
    plugins.push(createPugFile(filename))
});

plugins.push(new HtmlWebpackPugPlugin());

let pathsToClean = [
    'public/js/*.*',
];

plugins.push(new CleanWebpackPlugin(pathsToClean));

module.exports = {
    mode: PRODUCTION ? "production" : "development",
    entry: entry,
    output: {
        path: path.join(__dirname, "./public/js/"),
        publicPath: "/js/",
        filename: "[name].[hash].js",
    },
    module: {
        rules: [{
            test: /\.(js|jsx)$/,
            use: ["babel-loader"],
            exclude: /node_modules/,
        },
        {
            test: /\.pug$/,
            use: 'pug-loader'
        }]

    },
    optimization: {
        minimizer: PRODUCTION ? [
            new UglifyJsPlugin({
                parallel: true
            })
        ] : []
    },
    plugins: plugins,
    devtool: "source-map"
};

function createPugFile(filename) {
    return new HtmlWebpackPlugin({
        inject: false,
        chunks: [filename],
        filename: `./../../views/scripts/${filename}.pug`, //uses different path then template.
        template: './views/scripts/webpacktemplate.pug'
    })
}
@negibouze
Copy link
Owner

@techsin Thanks for your question. This plugin is extension for the HTML Webpack Plugin. It is intended to convert HTML Webpack Plugin output to pug, it does not operate independently.

@techsin
Copy link
Author

techsin commented Nov 13, 2018

I'm using const HtmlWebpackPlugin = require('html-webpack-plugin');

@negibouze
Copy link
Owner

@techsin
Sorry for my late reply.
I reconfirmed your first comment.
you using "pug-loader".
If possible, please try without using "pug-loader".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants