के साथ एक परियोजना को ठीक से कैसे संकलित करें मैं बैबेल के साथ खेलने की कोशिश कर रहा हूं, लेकिन यह मेरे लिए अच्छा काम नहीं करता है।बेबेल और ग्रंट
मेरे परियोजना सरल है
|-project/
|---src/
|-----index.html
|-----main.js
|-----module.js
|---Gruntfile.js
|---package.json
index.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Test</title>
<script src="main.js" type="application/javascript"></script>
</head>
<body>
<p>Simple html file.</p>
</body>
</html>
main.js
import * as math from "./module";
async function anwser() {
return 42;
}
(function main() {
anwser().then((v) => {
console.info(v);
});
console.log(math.sum(5, 5));
})();
module.js
export function sum(x, y) {
return x + y;
}
Gruntfile.js
module.exports = function(grunt) {
grunt.initConfig({
"babel": {
"options": {
"sourceMap": true,
"experimental": true
},
dist: {
files: [{
"expand": true,
"cwd": "src/",
"src": ["**/*.js"],
"dest": "build/",
"ext": ".js"
}]
}
},
htmlmin: {
dist: {
options: {
removeComments: true,
collapseWhitespace: true
},
files: [{
"expand": true,
"cwd": "src/",
"src": ["**/*.html"],
"dest": "build/",
"ext": ".html"
}]
}
},
watch: {
scripts: {
files: 'src/*.js',
tasks: ["babel"]
},
html: {
files: 'src/*.html',
tasks: ["htmlmin"]
}
}
});
grunt.loadNpmTasks('grunt-babel');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-htmlmin');
grunt.registerTask("default", ["babel", "htmlmin"]);
};
मैं घुरघुराना चलाने के लिए, सब कुछ संकलन। लेकिन मैं अपेक्षित परिणाम का उपयोग नहीं कर सकता।
सबसे पहले, ब्राउज़र require is not defined
कहता है, इसलिए मैं अपने HTML में require.js जोड़ता हूं।
फिर, मैं Error: Module name "module" has not been loaded yet for context: _. Use require([]) http://requirejs.org/docs/errors.html#notloaded
मिल मैं थोड़ा इन सब के बारे में उलझन में हूँ। मैं अपना कोड कैसे काम कर सकता हूं?
या हो सकता है और भी बेहतर: 'UMD' –