Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for webpack resolve configs to be passed directly #908

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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