quilljs / webpack-example

28 stars 29 forks source link

Should use 'resolve' package to specify alias #4

Closed cutephoton closed 9 months ago

cutephoton commented 4 years ago

The use of hard coded paths can lead to issues in some environments (for example, when using yarn workspaces). Hard coding is also not a great idea, in general. Using the resolve package, a small change to the webpack.conf.js would avoid potential issues.

const resolve                   = require('resolve');
const PKG_QUILL                 = resolve.sync('quill', { basedir: __dirname });
const PKG_PARCHMENT             = resolve.sync('parchment', { basedir: __dirname });
...
module.exports = {
  ...
  resolve: {
    alias: {
      'parchment': PKG_PARCHMENT,
      'quill$': PKG_QUILL,
    }
  },

Q: Why do you need an explicit quill$?

Alternatively, wouldn't this also work?

...
module.exports = {
  ...
  resolve: {
    modules:        module.paths
  },

JS not my day job... so I don't fully understand the nuances of webpack so I'm not clear on whether that's a terrible idea?

I also had other issues because I make things too complicated for myself. The most confusion one involved SVG files. Using ['file-loader', 'html-loader'] to store the individual assets as files won't work. It causes the toolbar to emit the filenames which are then interpreted as HTML (and not properly formed <svg src=...>). I would have thought there would be a better way to handle conflicts like this across multiple packages.

luin commented 9 months ago

Closing as it's not needed anymore in v2.