ericmmartin / ng-package-constants-loader

Webpack loader to generate an Angular constants module from values in your projects package.json file.
MIT License
1 stars 0 forks source link

webpack 4 can't run this loader #2

Open weiting-tw opened 5 years ago

weiting-tw commented 5 years ago

When I upgrade webapck 4, and run build. I got this error message:

ERROR in ./config.json Module parse failed: Unexpected token a in JSON at position 0 while parsing near 'angular.module("app....' You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token a in JSON at position 0 while parsing near 'angular.module("app....'

OskarPersson commented 5 years ago

Webpack 4 requires the type parameter when transforming JSON to JS:

module: {
  rules: [
    {
      // Let's take our config file by absolute url
      test: path.resolve(__dirname + 'package.json'),
      use: {
        loader: 'ng-package-constants-loader',
        options: {
          moduleName: 'app.constants' // name of the angular module
          configKey: 'config.all', // object to pull from package.json
          wrap: 'es6' // es6, true (default), false
        }
      },
      type: 'javascript/auto'
    }
  ]
}