Merge pull request #7034 from webpack/feature/import_ignore
Add comment directive to disable import parsing
This commit is contained in:
commit
aeaa877ed6
|
@ -33,6 +33,23 @@ class ImportParserPlugin {
|
|||
|
||||
const importOptions = parser.getCommentOptions(expr.range);
|
||||
if (importOptions) {
|
||||
if (typeof importOptions.webpackIgnore !== "undefined") {
|
||||
if (typeof importOptions.webpackIgnore !== "boolean") {
|
||||
parser.state.module.warnings.push(
|
||||
new UnsupportedFeatureWarning(
|
||||
parser.state.module,
|
||||
`\`webpackIgnore\` expected a boolean, but received: ${
|
||||
importOptions.webpackIgnore
|
||||
}.`
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// Do not instrument `import()` is `webpackIgnore` is `true`
|
||||
if (importOptions.webpackIgnore) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof importOptions.webpackChunkName !== "undefined") {
|
||||
if (typeof importOptions.webpackChunkName !== "string") {
|
||||
parser.state.module.warnings.push(
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const should = require("should");
|
||||
|
||||
it("should be able to ignore import()", () => {
|
||||
const source = fs.readFileSync(path.join(__dirname, "bundle1.js"), "utf-8");
|
||||
should(source).containEql(`import(/* webpackIgnore: true */ "./other2.js")`);
|
||||
should(source).not.containEql(`import(/* webpackIgnore: false */ "./other3.js")`);
|
||||
});
|
|
@ -0,0 +1,2 @@
|
|||
import(/* webpackIgnore: true */ "./other2.js");
|
||||
import(/* webpackIgnore: false */ "./other3.js");
|
|
@ -0,0 +1 @@
|
|||
export default "other2";
|
|
@ -0,0 +1 @@
|
|||
export default "other3";
|
|
@ -0,0 +1,12 @@
|
|||
module.exports = {
|
||||
entry: {
|
||||
bundle0: "./index.js",
|
||||
bundle1: "./other.js"
|
||||
},
|
||||
output: {
|
||||
filename: "[name].js"
|
||||
},
|
||||
node: {
|
||||
__dirname: false
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue