Webpack plugin that update cache for requirejs,replace requirejs urlArgs
base on assets-webpack-plugin
For example, given the following webpack config:
see ./example/
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):
require.config({
"paths": {
"index": "index.js?v=89b820adce324ffcdeb3675767248d32"
},
"baseUrl": ""
})
index.html
...
<script type="text/javascript" src="./require.js"></script>
<script type="text/javascript" src="./main.js"></script>
<script type="text/javascript">
require(['./index']);
</script>
...
npm install requirejs-webpack-plugin --save-dev
You can pass the following options:
Optinal. main.js
by default.
Name for the created json file.
new requirejsPlugin({filename: 'main.js'})
Optional. Defaults to the current directory.
Path where to save the file.
new requirejsPlugin({path: path.join(__dirname, 'app')})
Optional. Defaults is JSON stringify function.
Formats the assets output.
new requirejsPlugin({
processOutput: function (assets) {
return 'require.config(' + JSON.stringify(assets) + ')'
}
})
RequireJS baseUrl config
RequireJS paths config module alias