Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions doc/manual.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 ====

Expand Down
11 changes: 8 additions & 3 deletions plugin/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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) {
Expand Down