Webpack plugin that update cache for requirejs,replace requirejs urlArgs
npm install requirejs-webpack-pluginjs
var path = require("path");
var requirejsPlugin = require('requirejs-webpack-plugin');
{
entry:{
"index":"./src/index.js"
},
output:{
path:path.join(__dirname, "app"),
publicPath:"",
filename:"[name].js"
},
plugins: [
new requirejsPlugin({
path: path.join(__dirname, 'app'),
filename: 'main.js',
baseUrl : '',
pathUrl : '',
processOutput: function (assets) {
return 'require.config(' + JSON.stringify(assets) + ')'
}
})
]
}
`
The plugin will output the following requirejs config file(./app/main.js):
`js
require.config({
"paths": {
"index": "index.js?v=89b820adce324ffcdeb3675767248d32"
},
"baseUrl": ""
})
`
Useage
index.html
`html
...
...
`
Install
`sh
npm install requirejs-webpack-plugin --save-dev
`
Options
You can pass the following options:
$3
Optinal. main.js by default.
Name for the created json file.
`js
new requirejsPlugin({filename: 'main.js'})
`
$3
Optional. Defaults to the current directory.
Path where to save the file.
`js
new requirejsPlugin({path: path.join(__dirname, 'app')})
`
$3
Optional. Defaults is JSON stringify function.
Formats the assets output.
`js
new requirejsPlugin({
processOutput: function (assets) {
return 'require.config(' + JSON.stringify(assets) + ')'
}
})
``