Merge pull request #7034 from webpack/feature/import_ignore

Add comment directive to disable import parsing
This commit is contained in:
Tobias Koppers 2018-04-24 19:53:48 +02:00 committed by GitHub
commit aeaa877ed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 0 deletions

View File

@ -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(

View File

@ -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")`);
});

View File

@ -0,0 +1,2 @@
import(/* webpackIgnore: true */ "./other2.js");
import(/* webpackIgnore: false */ "./other3.js");

View File

@ -0,0 +1 @@
export default "other2";

View File

@ -0,0 +1 @@
export default "other3";

View File

@ -0,0 +1,12 @@
module.exports = {
entry: {
bundle0: "./index.js",
bundle1: "./other.js"
},
output: {
filename: "[name].js"
},
node: {
__dirname: false
}
};