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

How to resolve paths in custom attributes using html-loader with this excellent loader? #3

Open
geekox86 opened this issue May 12, 2018 · 2 comments

Comments

@geekox86
Copy link

Hi,

I have a Vue component template in pug with a prop called "pictureUrl" that I want to use with this value "~root/assets/icons/search-grey.png". However, I want Webpack to resolve this path to its base64 dataurl content using html-loader, url-loader, or any other loader.

How can I achieve this while using your loader?

@geekox86
Copy link
Author

btw, this is what I get when trying to use html-loader with this loader:

text "module.exports = "\n" outside root element will be ignored

@geekox86
Copy link
Author

geekox86 commented May 13, 2018

import * as path from 'path'
import { Configuration, NamedModulesPlugin, HotModuleReplacementPlugin } from 'webpack'
import { VueLoaderPlugin } from 'vue-loader'
import * as WebpackShellPlugin from 'webpack-shell-plugin'
import * as HtmlWebpackPlugin from 'html-webpack-plugin'
import * as HtmlWebpackInlineSourcePlugin from 'html-webpack-inline-source-plugin'

const config: Configuration = {
  mode: 'development',
  context: path.resolve(__dirname),
  entry: path.resolve(__dirname, 'index.ts'),
  output: {
    path: path.resolve(__dirname, 'bundles'),
    filename: 'index.js'
  },
  resolve: {
    alias: {
      root: path.resolve(__dirname),
      '~root': path.resolve(__dirname)
    }
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        test: /\.ts$/,
        loader: 'ts-loader',
        options: {
          appendTsSuffixTo: [/\.vue$/]
        }
      },
      {
        test: /\.pug$/,
        use: [
          {
            loader: 'html-loader',
            options: {
              attrs: ['customComponent:customUrl']
            }
          },
          'pug-plain-loader'
        ]
      },
      {
        test: /\.scss$/,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: {
              alias: {
                root: path.resolve(__dirname)
              }
            }
          },
          'sass-loader'
        ]
      },
      {
        test: /\.(jpg|jpeg|png|gif|svg|ttf|woff|woff2|eot)$/,
        loader: 'url-loader',
        options: {
          limit: 1048576
        }
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new NamedModulesPlugin(),
    new WebpackShellPlugin({
      onBuildStart: 'rm -rf bundles/*',
      onBuildEnd: 'rm -f bundles/index.js'
    }),
    new HtmlWebpackPlugin({
      template: path.resolve(__dirname, 'index.html'),
      inlineSource: /\.js$/
    }),
    new HtmlWebpackInlineSourcePlugin(),
    new HotModuleReplacementPlugin()
  ],
  devtool: 'source-map',
  devServer: {
    port: 8080,
    contentBase: path.resolve(__dirname, "bundles"),
    compress: true,
    hot: true
  }
};

export default config;

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

1 participant