Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The order of script #4

Open
GuichiZhao opened this issue Oct 23, 2019 · 3 comments
Open

The order of script #4

GuichiZhao opened this issue Oct 23, 2019 · 3 comments

Comments

@GuichiZhao
Copy link

I want to place asset script tag before main.js but after packages, how that possible

@jharris4
Copy link
Owner

Sorry for the very delayed response to this, I'm only just seeing it now.

You can control whether scripts are appended or prepended via the append option on each tag/script.

There are a couple of examples in the README, or if you provide a more specific example I can help get it working properly

@GuichiZhao
Copy link
Author

GuichiZhao commented May 25, 2020

@jharris4


'moment': {
    copy: [
        {
            from: 'moment.js',
            to: 'moment.js'
        },
        {
            from: 'locale/zh-cn.js',
            to: 'zh-cn.js'
        }
    ],
        scripts: [
            {
                variableName: 'moment',
                path: 'moment.min.js',
                devPath: 'moment.js'
            },
            {
                path: 'zh-cn.js'
            }
        ]
},


From the moment package, I need to copy out two files and generate two script individually. Say, moment.js which is the moment core and zh-cn.js which is the locale file.

However, the generated html is something like this:

Screen Shot 2020-05-25 at 6 03 05 pm

As you can see, zh-cn.js is appended after AFTER main.js for some reason(a bug?), such behavior breaks the logic of code as zh-cn.js will change the moment locale automatically. So the locale set in main.js not work

@jharris4
Copy link
Owner

As documented in the README, the root options of the plugin have an option called prependExternals which defaults to true.

The description is: Whether to default append to false for any <script> tag that has an external or variableName option specified

So what's happening is that this script:

{
  variableName: 'moment',
  path: 'moment.min.js',
  devPath: 'moment.js'
}

is getting prepended, whereas this script:

{
  path: 'zh-cn.js'
}

is getting appended.

So if that's not what you wanted, then you should change the options of the plugin, probably to something like this (adding append: false option for zh-cn.js):

'moment': {
    copy: [
        {
            from: 'moment.js',
            to: 'moment.js'
        },
        {
            from: 'locale/zh-cn.js',
            to: 'zh-cn.js'
        }
    ],
        scripts: [
            {
                variableName: 'moment',
                path: 'moment.min.js',
                devPath: 'moment.js'
            },
            {
                path: 'zh-cn.js',
                append: false
            }
        ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants