我已经用 Yarn 安装了 Resumablejs,我在 node_module 文件夹中看到了它。
Webpack.config.js
Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// only needed for CDN's or sub-directory deploy
//.setManifestKeyPrefix('build/')
/*
* ENTRY CONFIG
*
* Add 1 entry for each "page" of your app
* (including one that's included on every page - e.g. "app")
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
*/
.addEntry('app', './assets/js/app.js')
....
var config = Encore.getWebpackConfig();
var path = require('path');
config.resolve.alias = {
'jquery': path.resolve(__dirname, 'node_modules/jquery/src/jquery'),
'resumablejs': path.resolve(__dirname, 'node_modules/resumablejs/resumable')
};
module.exports = config;
包.json
"dependencies": {
...
"resumablejs": "^1.1.0",
...
}
应用程序.js
/*
* Welcome to your app's main JavaScript file!
*
* We recommend including the built version of this JavaScript file
* (and its CSS file) in your base layout (base.html.twig).
*/
// any CSS you require will output into a single css file (app.css in this case)
require('../css/app.scss');
const $ = require('jquery');
global.$ = global.jQuery = $;
require('resumablejs');
...
import './EntriesJs';
条目Js
import AppScripts from './js/appScripts';
export {
AppScripts
}
在我的 app.js 中我已经声明了它require('resumablejs');
,然后在我的文件中我想像这样使用它:
module.exports = function (uploadJs) {
return filesUploadScript();
};
function filesUploadScript() {
(function () {
console.log('js loaded...');
var uploaderWidgetProperties = $('#_f-uploader-widget-properties');
var r = new Resumable({ ... });
但此时我收到以下错误:
Uncaught ReferenceError: Resumable is not defined
我很难理解 Webpack,所以任何帮助都会很棒。