Preact-cli: npm run build building with system url path

Created on 20 May 2017  路  9Comments  路  Source: preactjs/preact-cli

When I run npm run build the sw.js is generated with system paths to the archives:

"C:/Users/jordao/projects/compra/build/1.chunk.82189a4e17c69863082e.js"

instead of:

"1.chunk.82189a4e17c69863082e.js"

Most helpful comment

You can also access webpack's root, although I can't remember what it's called now.

All 9 comments

Ah yeah. I think something needs to tell the sw plugin what webpacks context directory was.

I remember using "stripPrefixMulti" in sw-precache plugin to fix this

new SWPrecacheWebpackPlugin({
    cacheId: pkg.name,
    filename: 'sw.js',
    minify: true,
    maximumFileSizeToCacheInBytes: 4194304,
    stripPrefixMulti: {
      'C:/dev/site/dist': '',
      '/home/travis/build/myname/site/dist': ''
    }
  }),

I think we can even just pass it process.cwd()

You can also access webpack's root, although I can't remember what it's called now.

yup yup. just figured we'd keep this bit generic since there might be a time when we want to support an "eject" feature.

Can we change it to this?

new SWPrecacheWebpackPlugin({
    filename: 'sw.js',
    navigateFallback: 'index.html',
    minify: true,
    staticFileGlobsIgnorePatterns: [
        /\.map$/,
        /push-manifest\.json$/
    ],
    stripPrefixMulti: {
         [process.cwd()]: ''
     }
})

Oh, if there only was a plugin which can do all that automatically. It would be such a bless 馃槑 馃槀

I believe this was fixed in 1.1.1?

Indeed it was, absolute paths are no longer there. Closing.

Was this page helpful?
0 / 5 - 0 ratings