Comments (7)
I will keep watch for the new version with fixed WEBPACK SERVE
config as its number 1 requirement for me. Till the time I will continue with the html-webpack-plugin.
Enjoy your holidays 🎉
Wish you Merry Christmas & Happy New Year 🥳
from pug-plugin.
Okay, when is the launch of next version?
In lunary 2022. Now we have Christmas and Sylvester :-)
Also, how can we dynamically inject JS and CSS (from SCSS) into the templates?
Add JavaScript source in template
script
include ./script.js
Add script
and link
in template
I'm not sure whether following works:
head
link(rel='stylesheet' href=require('./path/to/src/main.scss'))
script(src='./path/to/src/main.js')
to replace original asset names with hached names like
main-fjg234g52j4.js
orstyles-fdwdf6w876w.css
can be used an asstes manifest plugin to replace names.
I compile the JS, SCSS via Webpack and add compiled names of assets in template:
head
link(rel='stylesheet' href='assets/css/styles.css')
script(src='assets/js/main.js')
Usage JavaScript Library in template
say-hello.js
module.exports = function (name) {
return `Hello ${name}!`;
}
pug template
- var sayHello = require('./say-hello.js')
h1 #{ sayHello('pug') }
Usage JSON data in template
data.json
[
{ "id": 1, "name": "abc" },
{ "id": 2, "name": "xyz" }
]
pug template
- var myData = require('./data.json')
each item in myData
div #{item.id} #{item.name}
P.S. more information and examples see by pug-loader
from pug-plugin.
Hello @kumardeepakxyz,
new version 1.2.3
is released.
from pug-plugin.
Hello @kumardeepakxyz,
thank you for usage.
Yes, I know about this limitation.
The webpack serve
is currently not supported yet.
But I work to add this feature.
The support webpack serve
will be added in next version of the plugin.
Currently works following modes:
webpack --mode=production
webpack --mode=development
webpack --watch
from pug-plugin.
Okay, when is the launch of next version?
Also, how can we dynamically inject JS and CSS (from SCSS) into the templates?
from pug-plugin.
@kumardeepakxyz Happy New Year!
Can you please try new version 1.2.0
, update your package.json
.
Now should work the webpack serve
.
You can try run the worked example:
clone https://github.com/webdiscus/pug-plugin.git
cd ./examples
npm i
npm run start
NEW: now supports dynamically require of styles directly in pug template without define the scss in webpack entry.
add to pug:
link(href=require('~Styles/styles.scss'))
add to webpack.config.js:
...
entry{
index: './src/templates/index.pug', // the pug template where is required style
},
plugins: [
new PugPlugin({
modules: [
PugPlugin.extractCss(), // add the plugin module to extract CSS
],
}),
],
module: {
rules: [
{
test: /\.pug$/,
loader: PugPlugin.loader,
},
{
test: /\.(css|sass|scss)$/,
type: 'asset/resource', // add this for usage in pug, like `link(href=require('~Styles/my-styles.scss'))`,
generator: {
filename: 'assets/css/[name].[hash].css', // save extracted style in public path
},
use: [ 'css-loader', 'sass-loader' ],
},
],
},
...
Now is no needed more the buggy mini-css-extract-plugin
;-)
For more details see in the example hello world
from pug-plugin.
Also, how can we dynamically inject JS and CSS (from SCSS) into the templates?
Hello @kumardeepakxyz,
I have new release 2.1.0
with dynamically injection of JS and SCSS.
Now is possible to use the source files of styles and scripts directly in pug.
link(href=require('./styles.scss') rel='stylesheet')
script(src=require('./main.js'))
The generated HTML contains hashed CSS and JS output filenames.
<link rel="stylesheet" href="/assets/css/styles.05e4dd86.css">
<script src="/assets/js/main.f4b855d8.js"></script>
The required styles and scripts in pug do not need to define in the webpack entry. All required resources will be automatically handled by webpack.
The example of webpack.config.js:
const PugPlugin = require('pug-plugin');
module.exports = {
entry: {
index: './src/index.pug' // extract html, css and js from pug
},
output: {
path: path.join(__dirname, 'dist/'),
publicPath: '/',
// output filename for JS files
filename: 'assets/js/[name].[contenthash:8].js'
},
plugins: [
new PugPlugin({
modules: [
PugPlugin.extractCss({
// output filename for CSS files
filename: 'assets/css/[name].[contenthash:8].css'
})
]
})
],
module: {
rules: [
{
test: /\.pug$/,
loader: PugPlugin.loader,
options: {
method: 'render', // for fastest compilation
}
},
{
test: /\.(css|sass|scss)$/,
use: ['css-loader', 'sass-loader']
}
],
},
// ...
};
from pug-plugin.
Related Issues (20)
- Very long project rebuild HOT 1
- Error RSPack with pug-plugin HOT 1
- i18next doesn't work after pug-plugin update to 5.0.0 (windows only) HOT 4
- How to complie the pug file to template function on pug-plugin v5 like pug-plugin v4? HOT 9
- How do I connect modules so that I can use them, instead of getting the resolved path to this module? HOT 2
- Some difficult questions (SCSS import as string)... HOT 7
- [FEATURE REQUEST] Preload support for font image audio video HOT 4
- Require manifest.json file HOT 3
- How to use Tailwind CSS with pug-plugin HOT 5
- Unexpected token '.' in Plugin.js issue. Can't compile my files HOT 1
- When connecting one page to js, a number is substituted HOT 4
- How to set the correct path to files connected via url in scss with Output Path option HOT 3
- Compilation fail on module contents change HOT 5
- The handling of @import at-rules in CSS is not supported. HOT 4
- [FEATURE REQUEST] Add ability to disable scripts compiling. HOT 2
- Failed to generate common named chunk with enabled pug plugin HOT 4
- Invalid url when using full path "publicPath" option HOT 5
- How to dynamically substitute a path in pug include HOT 1
- Issue with imports in required scripts HOT 7
- handling pug in webpack setupMiddlewares
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pug-plugin.