vigetlabs / blendid

A delicious blend of gulp tasks combined into a configurable asset pipeline and static site builder
MIT License
4.97k stars 682 forks source link

Rails can't find js files in development mode? [Blendid v4.1.1] #459

Closed amoshydra closed 6 years ago

amoshydra commented 7 years ago

Related to https://github.com/vigetlabs/blendid/issues/330 I am having problem with getting the app.js also using Blendid v4.1.1

yarn run blendid -- build is able to produce the correct asset_path @ http://localhost:3000/assets/gulp/javascripts/app.js

In development, the browser is expecting the app.js from the same path (http://localhost:3001/assets/gulp/javascripts/app.js) also. However it is not available (404).

The app.js is however accessible from localhost:3001/javascripts/app.js

path-config.json

{
  "src": "./styleguide/src/assets/toolkit",
  "dest": "./public/assets/gulp",

  "javascripts": {
    "src": "../../../../gulpfile.js/assets/javascripts",
    "dest": "javascripts"
  }
  ...

The only thing I customise from the webpack config is webpackConfig.resolve.modules

webpackConfig.resolve.modules = [
  path.resolve(pathA, moduleA),
  path.resolve(pathB, moduleB),
  'node_modules',
];

Other details:

amoshydra commented 7 years ago

https://github.com/vigetlabs/blendid/blob/master/gulpfile.js/lib/webpack-multi-config.js#L19

  const jsSrc = path.resolve(process.env.PWD, PATH_CONFIG.src, PATH_CONFIG.javascripts.src)
  const jsDest = path.resolve(process.env.PWD, PATH_CONFIG.dest, PATH_CONFIG.javascripts.dest)
  const publicPath = pathToUrl(TASK_CONFIG.javascripts.publicPath || PATH_CONFIG.javascripts.dest, '/')
  const rev = TASK_CONFIG.production.rev && env === 'production'

I have always thought that if we didn't define the publicPath in TASK_CONFIG, it will be default to PATH_CONFIG.dest + PATH_CONFIG.javascript.dest + /.

Apparently that is not the case in here.

My current workaround for this is to change the publicPath during development

  customizeWebpackConfig(webpackConfig, env, webpack) {
    if (env === 'development') {
      const publicPath = path.join(config.dest.replace('./public/', ''), config.javascripts.dest, '/');
      webpackConfig.output.publicPath = publicPath;
    }

Update:

It looks like the publicPath is incorrectly set for production env too: publicPath === javascripts/. However, this does not affect the output of the assets file and manifest as they will be using jsDest.

So I could actually specify the publicPath like this inside task-config directly

publicPath: path.join(config.dest.replace('./public/', ''), config.javascripts.dest, '/'),
crstin commented 7 years ago

Does not work for me either. When I run rails s and yarn run blendid, localhost:3001 has no access to the app.js file.

@amoshydra: Unfortunately your solution didn't help me. Does it still work for you?

I'm on:

rails 5.1.3
blendid 4.2.0

Nevermind, it's working on default config now, but I'm not sure why.