Skip to content

Instantly share code, notes, and snippets.

@aymericbeaumet
Last active November 16, 2018 14:46
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save aymericbeaumet/7e7ef5e31e17cff60a1d to your computer and use it in GitHub Desktop.
Save aymericbeaumet/7e7ef5e31e17cff60a1d to your computer and use it in GitHub Desktop.
node_modules/
npm-debug.log
bundle.js
npm install
npm run build
open index.html
var angular = require('angular');
var app = angular.module('app', [
require('angular-local-storage'),
]);
app.run(function(localStorageService) {
if (!localStorageService.get('lastVisit')) {
angular.element('body').text('Hello stranger!');
} else {
angular.element('body').text('Welcome back!');
}
localStorageService.set('lastVisit', Date.now());
});
<html>
<head>
<script src="bundle.js"></script>
</head>
<body ng-app="app">
</body>
</html>
{
"private": true,
"homepage": "https://aymericbeaumet.com/properly-shim-angularjs-applications-using-browserify",
"author": "Aymeric Beaumet",
"license": "UNLICENSE",
"scripts": {
"build": "browserify app.js -o bundle.js"
},
"dependencies": {
"angular": "1.3.14",
"angular-local-storage": "0.1.5",
"jquery": "2.1.3"
},
"browser": {
"angular": "./node_modules/angular/angular.js",
"angular-local-storage": "./node_modules/angular-local-storage/dist/angular-local-storage.js"
},
"browserify-shim": {
"angular": {
"depends": "jquery:jQuery",
"exports": "angular"
},
"angular-local-storage": {
"depends": "angular",
"exports": "angular.module('LocalStorageModule').name"
}
},
"browserify": {
"transform": [
"browserify-shim"
]
},
"devDependencies": {
"browserify": "9.0.3",
"browserify-shim": "3.8.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment