From d70c20d42c7ea0c057ab644d20913d67ee5fc8a8 Mon Sep 17 00:00:00 2001 From: Eloy Toro Date: Thu, 18 May 2017 13:20:07 -0500 Subject: [PATCH 1/2] support alias field --- plugin/webpack.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/plugin/webpack.js b/plugin/webpack.js index 7192563d..71e49f69 100644 --- a/plugin/webpack.js +++ b/plugin/webpack.js @@ -15,14 +15,15 @@ var path = require("path"); var ResolverFactory = require("enhanced-resolve").ResolverFactory; var SyncNodeJsInputFileSystem = require("enhanced-resolve/lib/SyncNodeJsInputFileSystem"); -function getResolver(modules, configPath) { +function getResolver(modules, configPath, alias) { var config = { unsafeCache: true, modules: modules || ["node_modules"], extensions: [".js", ".jsx", ".json"], aliasFields: ["browser"], mainFields: ["browser", "web", "browserify", "main"], - fileSystem: new SyncNodeJsInputFileSystem() + fileSystem: new SyncNodeJsInputFileSystem(), + alias: alias } var webpackConfig = (configPath && fs.existsSync(configPath)) ? require(configPath) : null if (typeof webpackConfig === 'function') { @@ -73,7 +74,11 @@ tern.registerPlugin("webpack", function(server, options) { var configPath = options.configPath || './webpack.config.js' var modules = options.modules || ['node_modules'] configPath = path.resolve(server.options.projectDir, configPath) - var resolver = getResolver(modules, configPath) + var alias = options.alias || {} + Object.keys(alias).forEach(function (key) { + alias[key] = path.resolve(server.options.projectDir, alias[key]) + }) + var resolver = getResolver(modules, configPath, alias) server.loadPlugin("commonjs") server.loadPlugin("es_modules") server.mod.modules.resolvers.push(function (name, parentFile) { From f7b7a3118eb6f03603f29e042545afb725000fbf Mon Sep 17 00:00:00 2001 From: Eloy Toro Date: Thu, 18 May 2017 13:24:46 -0500 Subject: [PATCH 2/2] update the docs --- doc/manual.txt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/manual.txt b/doc/manual.txt index a7ffce67..31e2f314 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -702,6 +702,23 @@ like: `configPath` should be a file path relative to `.tern-project`, you can omit it if they're in the same folder. +You cal also pass the `"module"` and `"alias"` keys directly instead +of passing the "configPath" + +[source,application/x-json] +---- +{ + "libs": [ + ], + "plugins": { + "webpack": { + "alias": { "lib": "./src/lib" }, + "modules": ["node_modules", "src"] + } + } +} +---- + [[plugin_requirejs]] ==== RequireJS plugin ====