ng-table
ng-table copied to clipboard
Strange issue when using webpack 2
Trying to upgrade to webpack 2, my build fails with the following error:
ERROR in ./~/ng-table/src/browser/pager.html Module build failed
Importing library (fails):
import * as ngTable from 'ng-table'
Requiring bundle (success):
require('ng-table/bundles/ng-table.js')
webpack config:
'use strict';
const webpack = require('webpack');
const NgAnnotatePlugin = require('ng-annotate-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const argv = require('yargs').argv;
const path = require('path');
module.exports = {
watch: false,
bail: true,
cache: true,
devtool: 'source-map',
entry: './typescript/app/app.ts',
output: {
path: path.resolve(__dirname, 'public'),
filename: 'build/main.bundle.js',
sourceMapFilename: '[name]-[chunkhash].map'
},
resolve: {
extensions: [
'.webpack.js',
'.web.js',
'.ts',
'.js'
],
alias: {
Raven: path.resolve(__dirname, 'node_modules/raven-js/src/raven.js')
}
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
}),
new NgAnnotatePlugin({
add: true
}),
new ExtractTextPlugin('build/[name].css'),
new HtmlWebpackPlugin({
filename: 'index.html',
inject: false,
hash: true,
cache: false,
template: 'ejs-loader!./typescript/index.html',
locals: {
environment: ENVIRONMENT,
production: process.env.PRODUCTION,
cdnDomain: CDN_DOMAIN,
backendUrl: BACKEND_URL,
releaseVersion: RELEASE_VERSION
}
}),
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // if no value is provided the sourcemap is inlined
test: /\.(ts|js)($|\?)/i // process .js and .ts files only
})
],
module: {
rules: [
{
test: /\.ts$/,
loader: 'awesome-typescript-loader'
},
{
test: /\.p?css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: [
'css-loader',
'postcss-loader'
]
})
},
{
test: /\.html$/,
exclude: /index.html$/,
use: [
{
loader: 'ngtemplate-loader',
options: {
relativeTo: path.resolve(__dirname, 'typescript')
}
},
{
loader: 'html-loader'
}
]
}
]
},
devServer: {
historyApiFallback: true
}
}
@faceleg have you been able to resolve that issue? I'm upgrading an AngularJS 1.5 app to Webpack 2 and see a GET http://app.finderbox.dev/app/ng-table/pager.html 404 (Not Found)
in the browser log.
@richtmat no I gave up and have been using webpack 1. Very interested in a solution though
I think this might actually be related to ngtemplate-loader
when specifying relativeTo
. I'm not getting any errors about not finding http://app.finderbox.dev/...
though. Might be related: webpack-contrib/html-loader#91. I'm using [email protected]
and [email protected]
.
On your test
for .html
, try removing relativeTo
and running Webpack. For me, it compiles fine, and the ng-table templates are added to the cache. Crack open your bundle and check it out.
Since we'll still need a prefix, I'm messing around with having a loader/test block for my app and a separate block for node_modules.
@mheppner unfortunately, for me it does not change a thing (here and https://github.com/esvit/ng-table/issues/969).
Only difference is that local templates are wrong as well. The url ending on .dev
is my local development url, you obviously cannot go there.
As I said in https://github.com/esvit/ng-table/issues/969 , I put the template content of the bundle in my files. The templates are put into the cache like this: $templateCache.put('ng-table/pager.html', html);
. I still struggle to find out if its a ng-table or webpack issue...
Up, same error here
Yo, I was able to solve this by changing how I import ng-table into my project. Importing directly from the bundle fixed it for me:
import 'ng-table/bundles/ng-table';
Works great: import 'ng-table/bundles/ng-table';
Same problema here. When importing like
import { ngTableModule } from 'ng-table';
then the header and footer are not bundled resulting in a HTTP 404.
Changing the import to
import 'ng-table/bundles/ng-table';
solves the header/footer problem but there's a glitch missing: the ^ and v sorting indicators are not shown. Sorting happens but there is no visual indication.
Any ideas?
@sargue This is a few months late, but I myself ran into the same problem with the sorting ^ and v not showing.
Add
import 'ng-table/bundles/ng-table.css';
:)
Thanks @jheimbouch , I can't try it because I'm no longer working on that project. But thanks anyway, I may be useful for somebody else.
I was able to get the HTML files compiling properly with Webpack by putting the following in my webpack.config.js:
module: {
rules: [
// ...
{ test: /ng-table\/.*\.html$/, use: ['ngtemplate-loader?requireAngular&relativeTo=/src/browser/&prefix=ng-table/', 'html-loader'] }
]
}
This also requires the NPM packages ngtemplate-loader
and html-loader
. Full details: https://github.com/esvit/ng-table/issues/969#issuecomment-703458126