Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

refactor: use ES Module export instead of CommonJS #69

Merged
merged 1 commit into from Mar 18, 2019

Conversation

niksy
Copy link
Contributor

@niksy niksy commented Mar 13, 2019

This PR contains a:

  • bugfix
  • new feature
  • code refactor
  • test update
  • typo fix
  • metadata update

Motivation / Use-Case

Since raw-loader now works only with Webpack 4+, we can take advantage of ES Modules and scope hoisting.

Breaking Changes

If developers use CommonJS style import (require), they should probably use const { default: str } = require('./string.txt') instead of import str from './string.txt', but I haven’t tested this. Should this be documented?

Additional Info

N/A.

@jsf-clabot
Copy link

jsf-clabot commented Mar 13, 2019

CLA assistant check
All committers have signed the CLA.

@codecov
Copy link

codecov bot commented Mar 13, 2019

Codecov Report

Merging #69 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #69   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines           7      7           
  Branches        1      1           
=====================================
  Hits            7      7
Impacted Files Coverage Δ
src/index.js 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7fa759c...74bb6bb. Read the comment docs.

@alexander-akait
Copy link
Member

@niksy Thanks for PR, yep, we need update docs too, also it is major release

@alexander-akait
Copy link
Member

Anyway code looks good, let's update docs and release new version

@alexander-akait
Copy link
Member

Also we have example for css-loader, let's add test for this, it will be great if you add tests in this PR, but we can do this in other PR

@niksy
Copy link
Contributor Author

niksy commented Mar 14, 2019

On what test in css-loader do you refer? I see only module.exports there.

@alexander-akait
Copy link
Member

We have in docs import css from '!!raw-loader!./file.css'; and will be great add test for this

@niksy
Copy link
Contributor Author

niksy commented Mar 18, 2019

Is writing test for that necessary? It doesn’t seem to be related to this loader, but it’s working for all loaders, so the test for that should be in Webpack core, not here.

@alexander-akait
Copy link
Member

/cc @niksy 👍 Ready for merge?

@niksy
Copy link
Contributor Author

niksy commented Mar 18, 2019

@evilebottnawi yup, good to go!

@alexander-akait alexander-akait merged commit 3c7bf2c into webpack-contrib:master Mar 18, 2019
@ViieeS
Copy link

ViieeS commented Mar 19, 2019

What about webpack's require.context? It stops working after update to 2.0

Code:

import {basename} from 'path';
import {templatesFactory} from '../app/templates-factory';

const ctx = require.context('assets/images/', true, /\.svg$/);

export const SvgSpriteBundle = angular.module('SvgSpriteBundle', [])
    .run(templatesFactory(ctx, 'assets/images/', key => basename(key)))
    .name;

@alexander-akait
Copy link
Member

You should use import().then()

@ViieeS
Copy link

ViieeS commented Mar 19, 2019

@ekulabuhov Yes, but it is asynchronous...

@alexander-akait
Copy link
Member

@ViieeS Can you create new issue with minimum reproducible test repo?

@ForsakenHarmony
Copy link

default exports though :/

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants