Home  >  Q&A  >  body text

node.js - webpack entry中的name是带路径的,结合ExtractTextPlugin使用时,如何得到不带路径的name

entry如下:

entry: {
    // 名字可以含路径,以用来将打包后的文件放入不同的路径
    'js/index': [
        path.resolve(src, 'index.js') // Your appʼs entry point
    ],
    'js/detail': [
        path.resolve(src, 'detail/detail.jsx') // Your appʼs entry point
    ],
    'lib/eg': [
        path.resolve(src, 'eg/lib.js') // Your appʼs entry point
    ],
  },

而在webpack的plugins中,使用了ExtractTextPlugin,配置是:

new ExtractTextPlugin("css/[name].css", {
        // allChunks: true
    })

最终打包出来的css文件,会被放到css/js/detail.css与,css/js/index.css,多了一级'js/',我想知道如何设置能让css文件统一放到css/*.css这样的路径下

PHPzPHPz2765 days ago501

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 15:43:28

    Originally, the trick of adding paths in names is to achieve modularization so that js and css can belong to the same module. I suggest you change the structure of your packaged files

    In other words, forcefully cancel the path:

    new ExtractTextPlugin("css/[contenthash:8].[name].css")

    If you do this, the file name will be a bit ugly, but at least the file level will be as you wish

    reply
    0
  • Cancelreply