Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import url from 'url';
import path from 'path';
import {
append,
constructors,
Expand Down Expand Up @@ -204,10 +205,13 @@ class ProcessHtml {
.replace(STYLE_URL_IMPORT_EXPR, replaceImportUrls)
.replace(STYLE_URL_EXPR, replaceStyleUrls));

const assetPath = `${path.relative(path.resolve(this.options.componentsDirectory || './src'), path.dirname(this.currentFilePath)).replace(new RegExp(`\\${path.sep}`, 'g'), '/')}/`;
const assetPathAttribute = assetPath.length > 1 ? ` assetpath=${assetPath} ` : '';
const domModuleContent = domModuleArray.map(node =>
ProcessHtml.htmlLoader(node, htmlLoaderOptions)
.replace(STYLE_URL_IMPORT_EXPR, replaceImportUrls)
.replace(STYLE_URL_EXPR, replaceStyleUrls));
.replace(STYLE_URL_EXPR, replaceStyleUrls)
.replace('<dom-module', `<dom-module${assetPathAttribute}`));

source += ProcessHtml.buildRuntimeSource(toBodyContent, RuntimeRegistrationType.BODY);
source += ProcessHtml.buildRuntimeSource(domModuleContent, RuntimeRegistrationType.DOM_MODULE);
Expand Down
8 changes: 8 additions & 0 deletions test/__snapshots__/loader.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ RegisterHtmlTemplate.register(\\"<dom-module id=\\\\\\"x-foo\\\\\\"><div></div><
"
`;

exports[`loader domModule transforms dom-modules with assetpath 1`] = `
"
const RegisterHtmlTemplate = require('polymer-webpack-loader/register-html-template');

RegisterHtmlTemplate.register(\\"<dom-module assetpath=bower_components/x-foo/ id=\\\\\\"x-foo\\\\\\"><div></div></dom-module>\\");
"
`;

exports[`loader domModule transforms multiple dom-modules 1`] = `
"
const RegisterHtmlTemplate = require('polymer-webpack-loader/register-html-template');
Expand Down
12 changes: 12 additions & 0 deletions test/loader.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,18 @@ describe('loader', () => {
'<div></div></dom-module>');
});

test('transforms dom-modules with assetpath', (done) => {
opts.resourcePath = 'src/bower_components/x-foo/x-foo.html';
opts.async = () => (err, source, map) => {
expect(err).toBe(null);
expect(normalisePaths(source)).toMatchSnapshot();
expect(map).toBe(undefined);
done();
};
loader.call(opts, '<dom-module id="x-foo">' +
'<div></div></dom-module>');
});

test('ignore non root level dom-modules', (done) => {
opts.async = () => (err, source, map) => {
expect(err).toBe(null);
Expand Down