I want to have a manifest in my ember app, because I want to use it on mobile devices and have some offline capabilities.
I have found the plugin ember-cli-deploy-manifest:
https://github.com/ember-cli-deploy/ember-cli-deploy-manifest
It is well documented in the readme and looked promising.
But how do I use the plugin?
I have installed it using this command:
ember install ember-cli-deploy-manifest
I build my app using this command:
ember build -prod
No manifest is created. I am probably missing some simple step, but can't figure it out. How do I tell ember build to use the plugin?
UPDATE
I followed the suggestion in the comment of the answer below. I dropped using the manifest-plugin and created a manifest file manually. Then the challenge is to get proper fingerprinted filenames in the manifest file.
In my ember-cli-build.js file I have:
module.exports = function(defaults) {
var app = new EmberApp(defaults, {
fingerprint: {
exclude: [],
extensions: ['js', 'css', 'png', 'jpg', 'gif', 'map'],
replaceExtensions: ['html','css','js', 'appcache']
}
});
...
My manifest file is called eea.appcache and is located in the /public folder. It is copied to the dist-folder during build.
However the content of the file (the list of filenames) are not fingerprinted. Filenames in the other files (html, css, js) are fingerprinted correctly.
Here is my public/eea.appcache:
CACHE MANIFEST
# 2016-03-15
# V 1.0
CACHE:
index.html
assets/vendor.css
assets/eea.css
assets/vendor.js
assets/eea.js
assets/img/Icon120x120.png
My buildstep is still:
ember build -prod
How to get the filenames in the manifets files updated with the MD5 fingerprint?
The ember-cli-deploy-manifest is for use with ember-cli-deploy.
So you need to run ember deploy -production once you have installed ember deploy.
Install ember-cli-deploy
ember install ember-cli-deploy
Then
ember deploy -production
I finally got it to work, but this solution is really hack'ish.
I figured this out by trial and error.
The broccoli-assets-rev has some tricky rules when it parses a file to find the filenames. The format that are normally used in a manifest file the filenames are not found by the parser.
But if the files are listed in the comments of the file with quotes and correct path is used, it will work.
If the manifest file is located in the root of the public folder it will end up in the root of the webpage. Then the paths will be as below.
My file looks like this:
CACHE MANIFEST
# 2016-03-15
# V 1.1
# '
# 'assets/vendor.css'
# 'assets/eea.css'
# 'assets/vendor.js'
# 'assets/eea.js'
# 'assets/img/Icon120x120.png'
CACHE:
index.html
assets/vendor.css
assets/eea.css
assets/vendor.js
assets/eea.js
assets/img/Icon120x120.png
NETWORK
*
Then the resulting built file looks like this:
CACHE MANIFEST
# 2016-03-15
# V 1.1
#
# 'assets/vendor-d41d8cd98f00b204e9800998ecf8427e.css'
# 'assets/eea-ddacde3bdf32d3f94c5a01a2054c6f72.css'
# 'assets/vendor-3229c2c849c3d52c0b362d9fee2106ad.js'
# 'assets/eea-4c760118f51f7402db2f0b6074b6960b.js'
# 'assets/img/Icon120x120-40b31b55211fb293dedf556a648aa47e.png'
CACHE:
index.html
assets/vendor-d41d8cd98f00b204e9800998ecf8427e.css
assets/eea-ddacde3bdf32d3f94c5a01a2054c6f72.css
assets/vendor-3229c2c849c3d52c0b362d9fee2106ad.js
assets/eea-4c760118f51f7402db2f0b6074b6960b.js
assets/img/Icon120x120-40b31b55211fb293dedf556a648aa47e.png
NETWORK
*
Related
Let's say I have a C++ project, which depends on an external package, which is fetched (by using a given git tag or source path) from the web as the first stage, then its artifact is passed to the job which builds my project.
I would like to speed up the build by caching the build of the dependency package somehow.
Ideally, I would like to build that external package once, then cache it for the subsequent pipelines without re-build it at the start of a new pipeline.
Then, if the git tag or the source path I use to fetch the external package changes (which would be the sign that I'm using a different version of the external package), then the package is built again and the cache replaced with the new version.
I'm trying to get this use-case from various pieces of GitLab CI documentation but I cannot find the right answer.
Does the template not work? link: https://gitlab.com/gitlab-org/gitlab-foss/-/blob/master/lib/gitlab/ci/templates/Python.gitlab-ci.yml
...
# Change pip's cache directory to be inside the project directory since we can
# only cache local items.
variables:
PIP_CACHE_DIR: "$CI_PROJECT_DIR/.cache/pip"
# Pip's cache doesn't store the python packages
# https://pip.pypa.io/en/stable/reference/pip_install/#caching
#
# If you want to also cache the installed packages, you have to install
# them in a virtualenv and cache it as well.
cache:
paths:
- .cache/pip
- venv/
...
I am using react-pdf to render a PDF file inline on my Django/Wagtail website.
To do this, I create a div in my HTML template with ID react, and I run a file called index.js which is a pretty straightforward React file that creates a DocumentViewer element and uses ReactDom to render it to the div with id 'react'.
I get an error when running my website on production when loading the worker file from my main bundle, specifically an error about how script worker.js cannot be accessed from origin 'example.com'
The exact code is not really relevant (although I can post it if necessary, but the thing that's giving me issues is loading the react-pdf worker.
I use the following import statement as the docs recommend:
import {Document, Outline, Page} from 'react-pdf/dist/entry.webpack';
I then use webpack to bundle and minify this file, with the following webpack.config.js:
var path = require("path");
var webpack = require('webpack');
var BundleTracker = require('webpack-bundle-tracker');
module.exports = {
context: __dirname,
entry: './project/app_name/static/js/index.js',
output: {
path: path.resolve('./project/app_name/static/bundles/'),
publicPath: '/static/bundles/',
filename: "[name]-[hash].js",
},
plugins: [
new BundleTracker({filename: './webpack-stats.json'}),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader']
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
}
};
This creates two files in the static/bundles folder of my Django application, main-<hash>.js and <hash>.worker.js.
The main-<hash>.js file creates a worker like this:
return new Worker(r.p+"<hash>.worker.js")
When I run my Django installation on my local machine, where I serve static files from the localhost there are no issues, which is pretty logical, since all files have the same origin.
However when I run it in production, where I serve my static files from a DigitalOcean space, Chrome produces the following error:
main-.js:38 Uncaught DOMException: Failed to construct 'Worker':
Script at
'https://ams3.digitaloceanspaces.com/-media/static/bundles/.worker.js'
cannot be accessed from origin 'https://www.example.com'.
I have already checked the CORS headers on that space, and everything seems to be in order.
When I use the curl command like this:
curl -v 'https://ams3.digitaloceanspaces.com/<project>-media/static/bundles/<hash>.worker.js' -X OPTIONS -H "Origin:https://example.com" -H "Access-Control-Request-Method: GET,PUT,HEAD,POST"
I get a 200 OK response.
I have no idea why Chrome would reject the loading of this script.
Is there something I'm missing in my webpack config, CORS settings or any other way browsers handle loading external scripts that I'm missing?
For anyone reading this: I figured out what the problem is.
Most browsers don't allow you to load a Worker from an external source, even if the CORS headers are all in order, the script loading is loaded from the same source as the worker, and the source is in my control.
Chrome, Firefox, and Safari all gave different errors, which was why I was confused as to what exactly happened.
The way I fixed this was by not loading the external worker, and running the code inline.
Two other ways to fix this are:
Serving the worker.js file from the same origin as the webpage.
Creating a worker through a blob URL (Like in this link).
The worker I used was loaded from a package inside my dependencies, I tried to configure Webpack to load this worker like this, but I could not get it to work.
So in the end I opted for not loading the worker at all.
Support CROS worker with a blob URL, you can do like this:
function workerCros(url) {
const iss = "importScripts('" + url + "');";
return URL.createObjectURL(new Blob([iss]));
}
const workerUrl = workerCros(new URL(workerFilePath, window.location).href);
const worker = new Worker(workerUrl);
I am bundling using Webpack 4.
I have multiple Webpack configurations exported in webpack.config.js.
First configuration is to bundle lient code targeting browsers.
Second configuration is to bundle server code targeting node.
I am specifying these browsers and node targets using browserslist in package.json.
I need to specify different browserslists for client and server bundles, but I only have one browserslist key in package.json.
How can I specify different browserslists using package.json?
You don't have to use package.json. If you create a file called .browserslistrc or browserslist at the root of your project, you can use a different configuration.
# Any general config goes at the very top, above any section headers
# ...
# Put section headers in [brackets]
[node]
supports es6-modules
[web]
>1% and not dead
Then call webpack and set BROWSERSLIST_ENV:
BROWSERSLIST_ENV=dev webpack -c webpack.dev.js # Build development
BROWSERSLIST_ENV=prod webpack -c webpack.prod.js # Build production
Your webpack command may be different depending on your configuration.
I'm very new to this area. I created the below folder structure:
Serverless
serverless.yml
function1.ts
models1.ts
models2.ts
<other json, config files>
The models files have shared code between different functions. I already installed serverless-webpack and other webpack. I also added the below into the .yml file:
service:
name: myapi
package:
include:
- models1.ts
- models2.ts
When I run serverless package, I can see function1.ts get compiled into .js file and included in .serverless's .zip file, but I don't see the models files get compiled. How do I get that work? Thanks
If your goal is to include the models1.ts and models2.ts
you can use this plugin https://github.com/webpack-contrib/copy-webpack-plugin
if you want those models to be included inside the generated bundle we need to make sure that your import resolution on webapck is well configured.
I cloned a rails project from github and trying to run rails generate rspec:install after running bundle install. The console gives following
`Usage:
rails new APP_PATH [options]
Options:
-r, [--ruby=PATH] # Path to the Ruby binary of your choice
# Default: /Users/sankethpurwar/.rvm/rubies/ruby-2.3.1/bin/ruby
-m, [--template=TEMPLATE] # Path to some application template (can be a filesystem path or URL)
[--skip-gemfile], [--no-skip-gemfile] # Don't create a Gemfile
-B, [--skip-bundle], [--no-skip-bundle] # Don't run bundle install
-G, [--skip-git], [--no-skip-git] # Skip .gitignore file
[--skip-keeps], [--no-skip-keeps] # Skip source control .keep files
-O, [--skip-active-record], [--no-skip-active-record] # Skip Active Record files
-S, [--skip-sprockets], [--no-skip-sprockets] # Skip Sprockets files
-d, [--database=DATABASE] # Preconfigure for selected database (options: mysql/oracle/postgresql/sqlite3/frontbase/ibm_db/sqlserver/jdbcmysql/jdbcsqlite3/jdbcpostgresql/jdbc)
# Default: sqlite3
-j, [--javascript=JAVASCRIPT] # Preconfigure for selected JavaScript library
# Default: jquery
-J, [--skip-javascript], [--no-skip-javascript] # Skip JavaScript files
[--dev], [--no-dev] # Setup the application with Gemfile pointing to your Rails checkout
[--edge], [--no-edge] # Setup the application with Gemfile pointing to Rails repository
-T, [--skip-test-unit], [--no-skip-test-unit] # Skip Test::Unit files
[--rc=RC] # Path to file containing extra configuration options for rails command
[--no-rc], [--no-no-rc] # Skip loading of extra configuration options from .railsrc file
Runtime options:
-f, [--force] # Overwrite files that already exist
-p, [--pretend], [--no-pretend] # Run but do not make any changes
-q, [--quiet], [--no-quiet] # Suppress status output
-s, [--skip], [--no-skip] # Skip files that already exist
Rails options:
-h, [--help], [--no-help] # Show this help message and quit
-v, [--version], [--no-version] # Show Rails version number and quit
Description:
The 'rails new' command creates a new Rails application with a default
directory structure and configuration at the path you specify.
You can specify extra command-line arguments to be used every time
'rails new' runs in the .railsrc configuration file in your home directory.
Note that the arguments specified in the .railsrc file don't affect the
defaults values shown above in this help message.
Example:
rails new ~/Code/Ruby/weblog
This generates a skeletal Rails installation in ~/Code/Ruby/weblog.
See the README in the newly created application to get going.`
Do I need to do any additional setup to work with an existing code base?
I think you are not running generator command from project directory. go to your project directory then run the command. If bundler in not installed then run gem install bundler after that run bundle install