Skip to content

Commit b33b444

Browse files
author
Eduard Kyvenko
committed
fix($config): Fixed the problem with global yarn installation
Create Elm App didn't work while globally installed by yarn, this commit adresses that issue Closes #102
1 parent f3a55d7 commit b33b444

File tree

5 files changed

+121
-104
lines changed

5 files changed

+121
-104
lines changed

config/paths.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
const path = require('path')
2+
const isGlobal = require('installed-by-yarn-globally')
23

3-
module.exports = {
4-
entry: path.resolve('./src/index'),
5-
dist: path.resolve('./dist'),
4+
const appRoot = process.cwd()
5+
6+
const paths = {
7+
appRoot,
8+
entry: path.resolve('./src/index.js'),
9+
dist: path.resolve('./build'),
610
template: path.resolve('./src/index.html'),
711
favicon: path.resolve('./src/favicon.ico'),
12+
elmPkg: path.resolve('elm-package.json'),
813
ownModules: path.resolve(__dirname, '../node_modules'),
914
scripts: path.resolve(__dirname, '../scripts'),
10-
elmMake: path.resolve(__dirname, '../node_modules/.bin/elm-make')
15+
elmMake: path.resolve(__dirname, '../node_modules/.bin/elm-make'),
16+
resolveLoaderModules: ['node_modules']
17+
}
18+
19+
// If installed globally by yarn, attemt to resolve loaders from the directory above.
20+
if (isGlobal) {
21+
paths.resolveLoaderModules.push(path.resolve(__dirname, '../../'))
1122
}
23+
24+
module.exports = paths

config/webpack.config.dev.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ module.exports = {
2020

2121
paths.entry
2222
],
23+
2324
output: {
2425

2526
pathinfo: true,
@@ -36,7 +37,7 @@ module.exports = {
3637
resolveLoader: {
3738

3839
// Look for loaders in own node_modules
39-
modules: [ paths.ownModules ],
40+
modules: paths.resolveLoaderModules,
4041
moduleExtensions: [ '-loader' ]
4142
},
4243

config/webpack.config.prod.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ const AssetsPlugin = require('assets-webpack-plugin')
88
const getClientEnvironment = require('./env')
99
const paths = require('../config/paths')
1010

11-
const root = process.cwd()
12-
1311
module.exports = {
1412

1513
bail: true,
@@ -24,7 +22,7 @@ module.exports = {
2422
path: paths.dist,
2523

2624
// Append leading slash when production assets are referenced in the html.
27-
publicPath: process.env.SERVED_PATH || '/',
25+
publicPath: './' || process.env.SERVED_PATH,
2826

2927
// Generated JS files.
3028
filename: 'js/[name].[chunkhash:8].js'
@@ -38,7 +36,7 @@ module.exports = {
3836
},
3937

4038
resolve: {
41-
modules: [ 'node_modules' ],
39+
modules: paths.resolveLoaderModules,
4240
extensions: [ '.js', '.elm' ]
4341
},
4442

@@ -123,7 +121,7 @@ module.exports = {
123121

124122
// Remove the content of the ./dist/ folder.
125123
new CleanWebpackPlugin([ 'dist' ], {
126-
root: root,
124+
root: paths.appRoot,
127125
verbose: false,
128126
dry: false
129127
}),

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
"fs-extra": "^2.1.2",
6060
"html-webpack-plugin": "2.28.0",
6161
"http-proxy-middleware": "^0.17.3",
62+
"installed-by-yarn-globally": "^0.1.2",
6263
"minimist": "1.2.0",
6364
"postcss-loader": "1.3.3",
6465
"prompt": "1.0.0",

0 commit comments

Comments
 (0)