Skip to content
This repository has been archived by the owner on Nov 15, 2018. It is now read-only.

Helps with requiring statics assets in webpack-encore

License

Notifications You must be signed in to change notification settings

skaryys/encore-require-assets-helper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Package is deprecated, work can be done without him thanks to @symfony/webpack-encore 0.21+.

encore-require-assets-helper

Creates .js file, which you can require in your js entry which you use in your @symfony/webpack-encore config.

Usage

Create file assets.config.js

var requireAssetsHelper = require("encore-require-assets-helper");
requireAssetsHelper(from,to,strip,add);

And in your javascript file, which you are using as Entry in webpack-encore:

//requires generated file
const assets = require("./assets.js");

Then run:

node assets.config.js

You should run this every time you add some images to your project.

In older versions of this package, It was recommended to write the requireAssetsHelper function inside the webpack.config.js. You can do it even now, but if you run encore with watch, it can be really slow, depending on amount and size of your images. The problem is mentioned here.

Configuration

The function has 4 parameters:

  • from A path to directory which includes files which you want to require
  • to A path to directory where you want to store your generated file
  • strip Optional, removes unwated strings from the path of required files
  • add A path prefix for all required files

Example

assets.config.js

var requireAssetsHelper = require("encore-require-assets-helper");

requireAssetsHelper(
    "./assets/images/**/*.{jpg,jpeg,png,gif,svg,ico}",
    "./assets/js/assets.js",
    "",
    "../../"
);

webpack.config.js

Encore
    ...
    .addEntry('app', './web/assets/js/main.js')
    ...
;

module.exports = Encore.getWebpackConfig();

main.js

...    
const assets = require("./assets.js");
...

About

Helps with requiring statics assets in webpack-encore

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published