I'm loading template dynamically in aurelia and while using webpack a view won't load unless added as <require from="..."></require>. When using aurelia-cli this was not necessary. Why? Does this have anything to do with how webpack loads modules?
I'm using aurelia with asp.net core template in Visual Studio 2017 generate by dotnet new aurelia as per https://github.com/EisenbergEffect/aspnetcore-aurelia-build-2017
<!-- this part was not required when using cli -->
<require from="../empty-report/empty-report"></require>
<compose id="printcontent" view-model="../${report.type}-report/${report.type}-report" model.bind="report"></compose>
my webpack.config.js
const path = require('path');
const webpack = require('webpack');
const { AureliaPlugin } = require('aurelia-webpack-plugin');
const bundleOutputDir = './wwwroot/dist';
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
return [{
stats: { modules: false },
entry: { 'app': 'aurelia-bootstrapper' },
resolve: {
extensions: ['.ts', '.js'],
modules: ['ClientApp', 'node_modules'],
},
output: {
path: path.resolve(bundleOutputDir),
publicPath: '/dist/',
filename: '[name].js'
},
module: {
rules: [
{ test: /\.ts$/i, include: /ClientApp/, use: 'ts-loader?silent=true' },
{ test: /\.html$/i, use: 'html-loader' },
{ test: /\.css$/i, use: isDevBuild ? 'css-loader' : 'css-loader?minimize' },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
]
},
plugins: [
new webpack.DefinePlugin({ IS_DEV_BUILD: JSON.stringify(isDevBuild) }),
new webpack.DllReferencePlugin({
context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json')
}),
new AureliaPlugin({ aureliaApp: 'boot' })
].concat(isDevBuild ? [
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
new webpack.optimize.UglifyJsPlugin()
])
}];
}
UPDATE #1
When edited bootstrapper to allow for resources, webpack builds, but loading the site I'll get an error
boot.ts
import 'isomorphic-fetch';
import { Aurelia, PLATFORM } from 'aurelia-framework';
import 'bootstrap/dist/css/bootstrap.css';
import 'bootstrap';
declare const IS_DEV_BUILD: boolean; // The value is supplied by Webpack during the build
export function configure(aurelia: Aurelia) {
aurelia.use
.standardConfiguration()
.feature(PLATFORM.moduleName('resources'));// /index makes no difference
//aurelia.use.plugin('aurelia-table');
//aurelia.use.plugin('aurelia-chart');
if (IS_DEV_BUILD) {
aurelia.use.developmentLogging();
}
aurelia.start().then(() => aurelia.setRoot(PLATFORM.moduleName('app/components/app/app')));
}
error:
aurelia-loader-webpack.js:187 Uncaught (in promise) Error: Unable to find module with ID: resources/index
at WebpackLoader.<anonymous> (aurelia-loader-webpack.js:187)
at step (aurelia-loader-webpack.js:36)
at Object.next (aurelia-loader-webpack.js:17)
at aurelia-loader-webpack.js:11
at Promise (<anonymous>)
at 146.__awaiter (aurelia-loader-webpack.js:7)
at WebpackLoader.146.WebpackLoader._import (aurelia-loader-webpack.js:152)
at WebpackLoader.<anonymous> (aurelia-loader-webpack.js:252)
at step (aurelia-loader-webpack.js:36)
at Object.next (aurelia-loader-webpack.js:17)
UPDATE #2:
I can confirm that the issue was the missing .feature('resources') or .feature(PLATFORM.moduleName('resources')), but even when adding index.ts (as advised here: http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/app-configuration-and-startup/6) I am not able to load features this way
I have organised my app as per above instructions on Aurelia page, but I still get the same error Error: Unable to find module with ID: resources/index. I have placed all my elements/components in resources folder and added index.ts in the same folder.
.globalResources('./empty-report/empty-report');) will need to use arequireto bring them into context; this was intentionally designed in order to avoid name clashing and improve clarity e.g. compared to other frameworks like angularjs - Ovidiu Dolhaaurelia.use.feature('...')is just like declaring all components inside as global resources - see this - Ovidiu Dolha.featureapproach expects to have anindexinside the folder you're registering -aurelia-cliapproach was probably doing this for you - now you must manually add this index in resources - a file that collects all your resources like thisexport function configure(aurelia) { aurelia.globalResources('./empty-report/empty-report')- Ovidiu Dolha