json-loader icon indicating copy to clipboard operation
json-loader copied to clipboard

feat: support scope hosting (`options.?`)

Open calvinmetcalf opened this issue 8 years ago • 4 comments

currently with webpack3 (unlike rollup) you can't do import {version} from './package.json'; this tries to fix that erring on the side of only including names for export when possible, it might make sense to be put behind a flag for now

see proj4js/proj4js#261

calvinmetcalf avatar Aug 17 '17 15:08 calvinmetcalf

CLA assistant check
All committers have signed the CLA.

jsf-clabot avatar Aug 17 '17 15:08 jsf-clabot

Wow just stumbled across this thanks to a tweet. Let's see if we can make this possible. Tricky, but why not. @webpack-contrib/admin-team this would be an awesome win for folks. We should try and help facilitate this change.

TheLarkInn avatar Sep 07 '17 16:09 TheLarkInn

so the main issue as far as I can tell is that the loader doesn't know what is being imported necessarily so we just have to proactively export as many legal identifiers as possible.

calvinmetcalf avatar Sep 07 '17 16:09 calvinmetcalf

json-loader still needs to support webpack =< v1.0.0 in the current semver range and I'm uncertain if modularization should be the default for the loader. For config files mandatory to be JSON (e.g package.json) this makes sense, but in case it is up to the user to choose the format => just use a .js file instead. This only works with webpack >=v2.0.0 (ES2015 Module Support && Tree Shaking) and therefore needs to be guarded against lower versions of webpack or released as 🏷 Major. Maybe this is even better implemented as a separate loader e.g (package-json-loader || config-loader...) instead. Using export default {json} is a breaking change nevertheless => require('file.json') => require('file.json').default

michael-ciniawsky avatar Sep 07 '17 20:09 michael-ciniawsky