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

Image path dev vs production build directory #72

Open
henry-martinez opened this issue Aug 29, 2016 · 4 comments
Open

Image path dev vs production build directory #72

henry-martinez opened this issue Aug 29, 2016 · 4 comments

Comments

@henry-martinez
Copy link

henry-martinez commented Aug 29, 2016

Hi I'm still getting used to webpack and the workflow so I'm not sure if it's an issue or if i'm going about it the wrong way.
I'd like to have a dev image path url and a different url path when i go to build for the production server.

For example:
While DEV'ing (npm start):

<img src="./img/logo.png" alt="">

and
BUILD (npm run build):

<img src="/angular/dist/img/logo.png" alt="">

Now, i've successfully updated the publicPath to properly build the css and js paths:

    config.output = isTestEnv ? {} : {
        path: root('dist'),
        publicPath: ENV === 'build' ? '/angular/dist/' : '',
        ...
    };

Unfortunately my image paths remain the same when i go to build so they don't display.

Am I missing something here?

Thanks, for any help.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/37383336-image-path-dev-vs-production-build-directory?utm_campaign=plugin&utm_content=tracker%2F32095848&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F32095848&utm_medium=issues&utm_source=github).
@cmelion
Copy link
Owner

cmelion commented Aug 29, 2016

Hmm, I'll have to think about that.

@henry-martinez
Copy link
Author

henry-martinez commented Aug 30, 2016

So i'm not sure if it's the most elegant approach but i used string replacement (a solutions i used with gulp in the past) as a workaround.

Using this webpack module:
https://github.com/jamesandersen/string-replace-webpack-plugin

and i added the following after the config.module block (in the webpack.config.js):

  if(ENV === 'build') {

    config.module.loaders.push(
      {
        test: /\.(html|scss)$/,
        loader: StringReplacePlugin.replace({
          replacements: [
            {
              pattern: /src="\.\/img\//ig,
              replacement: function (match, p1, offset, string) {
                return 'src="/angular/dist/img/';
              }
            },
            {
              pattern: /url\('\.\/img\//ig,
              replacement: function (match, p1, offset, string) {
                return "url('/angular/dist/img/";
              }
            }
          ]})
      }
    );
  }

@cmelion
Copy link
Owner

cmelion commented Sep 19, 2016

@henry-martinez would you be interested in doing a PR?

@henry-martinez
Copy link
Author

@cmelion unfortunately i'm up to my neck with projects and wouldn't be able to find the time anytime soon.

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