├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── example ├── README.md ├── index.html ├── package.json ├── src │ └── hello_world.dart └── webpack.config.js ├── index.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 28 | node_modules 29 | 30 | # Optional npm cache directory 31 | .npm 32 | 33 | # Optional REPL history 34 | .node_repl_history 35 | 36 | *.tgz 37 | 38 | example/bundle.js 39 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 18 | .grunt 19 | 20 | # node-waf configuration 21 | .lock-wscript 22 | 23 | # Compiled binary addons (http://nodejs.org/api/addons.html) 24 | build/Release 25 | 26 | # Dependency directory 27 | # https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git 28 | node_modules 29 | 30 | # Optional npm cache directory 31 | .npm 32 | 33 | # Optional REPL history 34 | .node_repl_history 35 | 36 | *.tgz 37 | 38 | example 39 | .npmignore 40 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Matt Dziuban 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Dart Webpack loader 2 | 3 | [![npm](https://img.shields.io/npm/v/dart-loader.svg)](https://www.npmjs.com/package/dart-loader) 4 | 5 | ### Usage 6 | 7 | This is a simple Webpack loader that shells out to dart2js to build a [Dart web app](https://webdev.dartlang.org/). 8 | 9 | To use it, first install the package: 10 | 11 | ```bash 12 | $ npm install --save dart-loader 13 | ``` 14 | 15 | then configure the loader in your Webpack config: 16 | 17 | ```js 18 | module.exports = { 19 | // ... 20 | module: { 21 | rules: [ 22 | { test: /\.dart$/, loader: 'dart-loader' }, 23 | // ... 24 | ] 25 | } 26 | } 27 | ``` 28 | 29 | Make sure you have the `dart2js` binary somewhere in your `PATH`. 30 | 31 | ### Example 32 | 33 | Check out the [example](example) directory for a simple Hello World example. 34 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Dart Webpack loader example 2 | 3 | This is a simple Hello World example of the [Dart Webpack loader](https://www.npmjs.com/package/dart-loader). 4 | 5 | ### Install dependencies 6 | 7 | ```bash 8 | $ npm install 9 | ``` 10 | 11 | ### Compile 12 | 13 | ```bash 14 | $ npm run compile 15 | ``` 16 | 17 | ### Serve 18 | 19 | Run 20 | 21 | ```bash 22 | $ npm run serve 23 | ``` 24 | 25 | then open http://localhost:8080 in your browser. 26 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Hello World 5 | 6 | 7 |
8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dart-loader-example", 3 | "version": "0.0.1", 4 | "description": "", 5 | "author": "Matt Dziuban", 6 | "license": "UNLICENSED", 7 | "scripts": { 8 | "compile": "webpack --progress", 9 | "serve": "http-server" 10 | }, 11 | "dependencies": { 12 | "dart-loader": "../", 13 | "http-server": "^0.9.0", 14 | "webpack": "^2.2.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /example/src/hello_world.dart: -------------------------------------------------------------------------------- 1 | import 'dart:html'; 2 | 3 | void main() { 4 | querySelector('#container').innerHtml = 'Hello World'; 5 | } 6 | -------------------------------------------------------------------------------- /example/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | entry: './src/hello_world.dart', 3 | output: { filename: 'bundle.js' }, 4 | module: { 5 | rules: [ 6 | { test: /\.dart$/, loader: 'dart-loader' } 7 | ] 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const child_process = require('child_process'); 2 | const fs = require('fs'); 3 | const path = require('path'); 4 | 5 | module.exports = function(source) { 6 | const callback = this.async(); 7 | const tmp = path.join(__dirname, 'tmp'); 8 | const fname = path.basename(this.resourcePath, '.dart'); 9 | const cmd = `dart2js -o '${path.join(tmp, `${fname}.js`)}' '${this.resourcePath}'`; 10 | child_process.execSync(`rm -rf '${tmp}'`); 11 | child_process.execSync(`mkdir -p '${tmp}'`); 12 | 13 | child_process.exec(cmd, function(error, stdout, stderr) { 14 | if (error) { return callback(error, null); } 15 | const out = fs.readFileSync(path.join(tmp, `${fname}.js`), 'utf8'); 16 | callback(null, out); 17 | }); 18 | }; 19 | 20 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dart-loader", 3 | "version": "0.0.1", 4 | "author": "Matt Dziuban", 5 | "description": "Dart loader module for webpack", 6 | "dependencies": { 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "git@github.com:mrdziuban/dart-loader" 11 | }, 12 | "main": "index.js", 13 | "license": "MIT" 14 | } 15 | --------------------------------------------------------------------------------