webpack-contrib / exports-loader Goto Github PK
View Code? Open in Web Editor NEWExports Loader
License: MIT License
Exports Loader
License: MIT License
Please give more example of how to use this. For instance an example showing exactly where those require lines mentioned go. A full file using this would be nice. .
require("exports-loader?file,parse=helpers.parse!./file.js");
// adds below code the the file's source:
// exports["file"] = file;
// exports["parse"] = helpers.parse;
require("exports-loader?file!./file.js");
// adds below code the the file's source:
// module.exports = file;
In what files is this needed?
Addition of webpack-defaults
& associated refactoring as a part of the next Major
release
Issue exists for status tracking across the organization.
Please do not close
Can you provide an example using webpack configuration?
I expected a valid build and export of the module.
Validation Error:
ValidationError: Invalid options object. Exports Loader has been initialized using an options object that does not match the API schema.
- options misses the property 'exports'. Should be:
non-empty string | object { name, syntax?, alias? } | [non-empty string | object { name, syntax?, alias? }, ...] (should not have fewer than 1 item)
It is clear I have the options in the config.
{
...
module: {
rules: [
{
test: path.resolve(__dirname, 'assets/public/js/templates.js'),
use: [
{
loader: 'expose-loader',
options: {
exposes: 'templates'
}
},
{
loader: 'exports-loader',
options: {
type: 'commonjs',
exports: 'single templates'
}
},
]
}
]
}
...
}
templates.js is a file with a single variable templates
. I want webpack to add the exports code module.exports = templates;
then expose that variable to the global scope so I can access window.templates
.
Simply use expose loader with exports loader.
Also note that exports loader works as expected when used by itself without expose-loader.
This issue is for a:
At webpack.config.js
I use following line : use: 'exports-loader?file'
I am trying to receive content of file
constant in index.js
:
import { file } from './globals.js';
console.log(file);
Result undefined
, but content of file
expected.
But ,if :
use: 'exports-loader?file,parse=helpers.parse'
import { file, parse } from './globals.js';
console.log(file, parse);
Results as expected.
Is this bug or how can I get only one variable please ?
Thanks.
This issue is for a:
module: {
rules: [{
test: '/\.js$/',
loader: 'exports-loader'
}]
}
let main = new Vue();
export default main;
exports['main'] = main; // this statement comes an error called "Uncaught ReferenceError: exports is not defined"
'main' can be a global variable in the html.
An error occurs when executing ' exports['main'] = main; ',
Set webpack's module like the above shows.
Using name interpolation while also renaming the export, as in a query like
import {foo} from 'exports-loader?[name]=global!./foo.js';
does not seem to work. It adds
exports.foo = foo;
to foo.js
, instead of
exports.foo = global;
This seems to happen because the loader first does interpolation on the keys of the query object, and then later uses these interpolated strings to look up the names of the globals that are to be exported.
5.1.15-arch1-1-ARCH
)11.15.0
6.9.0
4.35.0
0.7.0
This issue is for a:
$ npx webpack
$ node dist/main.js
See this gist.
The example should print 42
.
It fails with a ReferenceError
for foo
, which it is accessing as a global when trying to export it from foo.js
.
Just clone the above gist and run the given commands.
`exports-loader?type=commonjs&exports=exports.toString()``
Or how can I reference the unknown exported token in loader query?
Don't break previous usage of this loader.
Getting the following error:
Module build failed (from ./node_modules/exports-loader/dist/cjs.js):
TypeError: this.getOptions is not a function
at Object.loader (/home/ssoloski/talon-ng/talon/node_modules/exports-loader/dist/index.js:23:24)
@ ./app/javascript/packs/application.js 10:0-42
Lets assume you have a basic js file which has no exports or any functions:
object-assign-detect.js
'assign' in Object
It would be great if you can wrap this in a default
export (along with a return)
export default function() {
return 'assign' in Object
}
import objectAssignDetect from 'exports-loader?....'
if (objectAssignDetect()) {
...
}
It would be very useful if there was a way to have the file name as a token when setting up a config for loading multiple modules under the same global namespace.
Example: exports-loader?NAMESPACE.[name]
For a real-world example, I'm using the three example modules, who all rely on and attach to the global THREE
namespace.
So a config for loading them could look like this:
{
test: /three\/examples\/js/,
use: ["imports-loader?THREE=three", "exports-loader?THREE.[name]"]
}
alias: {
"three-examples": path.join(__dirname, "./node_modules/three/examples/js")
},
And I could load them like this:
import ColladaLoader from "three-examples/loaders/ColladaLoader";
import XLoader from "three-examples/loaders/XLoader";
I use the lib js-aruco which is browser only. Thats why I try to shim that lib. I do it this way:
module.exports = require('exports-loader?CV!../js-aruco/src/cv.js')
In the bundle I can see the libraray included - but the module.exports = CV
is missing.
However - a similar case is working:
module.exports = require('imports-loader?CV=./cv.js!exports-loader?AR!../js-aruco/src/aruco.js')
Here I can see the export. Ofc this code fails because it requires CV do be loaded correctly which is not the case.
I am using webpack v3
// EDIT: When requireing the module directly from my app require('./modules/cv.js')
it exports the module. However cv still cant see ar because its put twice in the bundle. One time with export and one time without.
It looks like the export loader is simply not executed
webpack: compiled successfully message.
webpack: es6-promise throws an error. attached the screenshot.
// webpack.config.js
// If your code blocks are over 20 lines, please paste a link to a gist
// (https://gist.github.com).
import "whatwg-fetch";
// additional code, HEY YO remove this block if you don't need it
use webpack with the next modules:
"whatwg-fetch": "latest"
"es6-promise": "^4.2.8",
"es6-promise-loader": "^1.0.2",
"exports-loader": "1.0.0",
the issue comes up when any "fetch" related module imported, if export-loader v1.0.0+ installed. there have been no issues with previous ones.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.