require.js text plugin adds “.js” to the file name

后端 未结 7 1058
旧时难觅i
旧时难觅i 2021-01-08 00:31

I\'m trying to work with requirejs and text plugin and I have weird problem.

I have two web servers:

  1. localhost:3000 - act as CDN and h
7条回答
  •  温柔的废话
    2021-01-08 00:59

    I've had trouble with the text plugin when working across domains and perhaps your two localhost servers are hitting this too.

    In the web inspector I saw that require.js was trying to fetch things like some-content.html.js instead of some-content.html.

    Are you running this code in development mode or building into a production set? When you bundle everything up the text plugin shouldn't have this same cross-domain trouble.

    Here's the API documentation part that tipped me off (from http://requirejs.org/docs/api.html):

    The baseUrl can be a URL on a different domain as the page that will load require.js. RequireJS script loading works across domains. The only restriction is on text content loaded by text! plugins: those paths should be on the same domain as the page, at least during development. The optimization tool will inline text! plugin resources so after using the optimization tool, you can use resources that reference text! plugin resources from another domain.

    Here's an article that helped me work around this for browsers that support CORS:

提交回复
热议问题