Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

import-assertions

xtuc4MIT0.0.4

Import Assertions loader for webpack

webpack, loader, module, assertions, attributes, tc39, proposal

readme

Import Assertions

See https://github.com/tc39/proposal-import-assertions.

Requires Babel v7.12.0 or higher.

Ensures the type of the file at webpack build time. Currently supported types are:

- json

import json from "./data" assert { type: "json" };

webpack loader

Add the following rule to your webpack configuration:

module: {
  rules: [
    {
        test: /\.jsx?$/,
        loader: "import-assertions"
    }
  ]
}

Example

See example in ./example.

It's a simple app that import a JSON file, or at least assumes so...

Build and run the example:

$ webpack && node dist/main.js
{ name: 'Sven' }

Try to uncomment the import to ./fake-data (line 2) and build the example you will see a JSON parse failure. This is because the fake-data file isn't actually JSON.

if you remove the assert { type: "json" } assertion from the import, build and run the example, you will see:

$ webpack && node dist/main.js
lol
{ name: 'Sven' }