Y
Y
yesworld2018-05-28 19:55:24
Node.js
yesworld, 2018-05-28 19:55:24

How to pass [name] entry point to file-loader/url-loader in webpack 4?

Hello.
The task is to set up WP4 for small projects, where N is the number of entry points.

entry: {
  app1: './src/App1/main.js',
  app2: './src/App2/main.js',
  ....
},
output: {
  path: path.resolve(__dirname, '../dist'),
  filename: '[name]/js/script.js',
},
module: {
  rules: [
      {
      test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
      loader: 'url-loader',
      options: {
          name: utils.assetsPath('[name].[hash:7].[ext]'),
          publicPath ...
      }

Almost everything works, but there was a problem with static. Images when building by default go to the dist/static folder , but I need them to go to the project folder dist/[EntryName]/static , depending on the [name] placeholders passed through the entry settings.
Those. the structure should look something like this:
5b0c336d77b80386922322.jpeg
There are a couple of ideas:
1. Create your own placeholder and pass the entry name into it, like app1, etc. But so far I have not studied this issue.
2. implement publicPath through a function, where to pull out [name] through a regular expression, but this is a hard crutch. :(

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
thehighhomie, 2018-06-10
@thehighhomie

The easiest way is to create a folder in pictures, for a specific entry point

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question